ocracy.registry#
Backend discovery, registration, and lazy loading.
An implemented backend is a subpackage of ocracy.backends that ships
two things:
config.pydefining aBACKEND_CONFIGdict (id, pip_install, capabilities,param_map, …), andadapter.pydefining anAdapterclass whoseread(image, **kwargs)returns anocracy.base.OcrResult.
This registry scans for those at first use, loads each adapter lazily (so
importing ocracy never imports heavy engine SDKs), and raises a friendly
pip install error if a backend’s dependency is missing. Third parties can
register their own backends at runtime via register_backend().
The design mirrors the sibling denote facade, adapted for OCR: the primary
capability is "read" (image -> text+layout), with optional extra capabilities
("tables", "math", …) declared per backend.
Module Attributes
The capability every general OCR backend provides. |
Functions
Clear all registered backends (useful for tests). |
|
|
Config + lazily-loaded adapter for a backend (raises on missing deps). |
|
A backend's |
|
Pick a sensible default backend id for a capability. |
|
Sorted ids of implemented backends, optionally filtered by capability. |
|
Register a backend at runtime (for third-party plugins). |
- ocracy.registry.PRIMARY_CAPABILITY = 'read'#
The capability every general OCR backend provides.
- ocracy.registry.clear_registry()[source]#
Clear all registered backends (useful for tests).
- Return type:
- ocracy.registry.get_backend(backend_id)[source]#
Config + lazily-loaded adapter for a backend (raises on missing deps).
- Return type:
- ocracy.registry.get_config(backend_id)[source]#
A backend’s
BACKEND_CONFIGwithout loading its adapter.- Return type:
- ocracy.registry.get_default_backend(capability='read', *, require_available=True)[source]#
Pick a sensible default backend id for a capability.
Strategy (OCR-tuned): prefer a backend explicitly flagged
default_forthe capability and whose dependency is importable; then any importable backend for the capability; then — ifrequire_availableis False or nothing is installed — the first registered candidate (using it will raise a helpful install error).- Return type:
- ocracy.registry.list_backends(capability=None)[source]#
Sorted ids of implemented backends, optionally filtered by capability.
A backend matches
capabilityif it appears in the backend’scapabilitieslist (the primary"read"is implied for all).