ontocast.util.optional¶
Helpers for importing optional dependencies with actionable error messages.
OntoCast ships a light core: the extraction pipeline, the in-memory triple and
vector stores, and the ontology tooling all work on a bare pip install
ontocast. Everything heavier -- LLM provider SDKs, document conversion,
external vector backends, the HTTP server -- lives behind an extra.
The cost of that split is that a missing package surfaces at call time rather
than at install time, so the error has to say exactly which extra to install.
:func:require centralises that message.
MissingDependencyError
¶
extra_for(module)
¶
install_hint(module, *, feature=None)
¶
Build the pip install guidance for a missing optional module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module
|
str
|
The importable module name that failed to resolve. |
required |
feature
|
str | None
|
Optional human-readable name of the capability that needs it. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A one-line message naming the extra to install. |
Source code in ontocast/util/optional.py
is_available(module)
¶
Return whether an optional module can be imported.
Used for capability gating -- deciding whether to expose a tool at all --
rather than for error reporting. Prefer :func:require when the caller
genuinely needs the module.
Source code in ontocast/util/optional.py
require(module, *, feature=None)
¶
Import an optional module or raise with an install hint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module
|
str
|
Fully qualified module name, e.g. |
required |
feature
|
str | None
|
Optional human-readable name of the capability that needs it, used to make the error message concrete. |
None
|
Returns:
| Type | Description |
|---|---|
ModuleType
|
The imported module. |
Raises:
| Type | Description |
|---|---|
MissingDependencyError
|
If the module cannot be imported. |