Plugin Authoring Guide¶
The iMednet SDK monorepo contains the following first-party packages:
imednet (Core SDK) — The foundational API client and SDK.
imednet-workflows — Opinionated data-extraction and query-management workflows.
imednet-sinks — Export sinks for data destinations.
imednet-tui — Interactive terminal user interface (TUI) plugin.
apache-airflow-providers-imednet — Apache Airflow integrations.
The built-in imednet-workflows package is the reference implementation for
third-party SDK plugins, while imednet-tui demonstrates CLI subcommand
registration through the imednet.cli_plugins entry-point group:
[project.entry-points."imednet.cli_plugins"]
tui = "imednet_tui.cli:setup_parser"
Any third-party package can register its own SDK or CLI plugin using the standard Python entry-point mechanism.
Optional-plugin CLI graceful-degradation verification¶
CLI commands that depend on optional plugins should be tested in two modes:
Plugin present: patch
importlib.util.find_spec(or module import) to return a module and assert the command runs.Plugin absent: patch discovery to return
None(or raiseImportError) and assert the command exits with code1and prints install guidance.
See tests/unit/cli/test_cli.py and tests/unit/cli/test_cli_export.py
for repository examples of this pattern.
Plugin authoring reference¶
How it works¶
The SDK supports typed synchronous and asynchronous Python entry-point groups
for extending functionality on ImednetSDK and
AsyncImednetSDK:
Workflows (``imednet.workflows`` and ``imednet.async_workflows``) —
sdk.workflowsis aWorkflowRegistrythat resolves synchronous adapters fromimednet.workflowsonImednetSDKand native asynchronous adapters fromimednet.async_workflowsonAsyncImednetSDK(falling back toimednet.workflowsentries that declaresupports_async = True). Each entry point is loaded and instantiated lazily on first attribute access by passing the active SDK facade.Export sinks (``imednet.sinks`` and ``imednet.async_sinks``) —
export()discoversExportSinkclasses inimednet.sinks, whileasync_export()discoversAsyncExportSinkclasses inimednet.async_sinks.Namespace plugins (``imednet.plugins``) — Top-level SDK namespaces such as
sdk.sinksquery theimednet.pluginsentry-point group (for example,sinks = "imednet_sinks.plugin:create_sinks") and invoke the registered factory with the SDK instance to return a mode-matched namespace (SinksNamespaceProtocolonImednetSDKandAsyncSinksNamespaceProtocolonAsyncImednetSDK).
If a workflow or plugin package is not installed, accessing the missing
workflow or namespace attribute raises AttributeError or
ImportError with installation guidance.
If a namespace plugin is installed under imednet.plugins but fails to
load (duplicate registration, broken import, or non-callable target), a
PluginLoadError is raised when loading the namespace.
Plugin contract¶
Workflow adapters registered under imednet.workflows accept
ImednetFacade, while asynchronous adapters
registered under imednet.async_workflows accept
AsyncImednetFacade and expose symmetric unprefixed
coroutine methods. Custom workflows registered only under imednet.workflows
default to synchronous-only and raise TypeError on
AsyncImednetSDK unless they also register an
imednet.async_workflows adapter or declare supports_async = True.
A namespace-level plugin factory registered under imednet.plugins satisfies
PluginProtocol (or SinksPluginProtocol,
returning SinksNamespaceProtocol /
AsyncSinksNamespaceProtocol or
SyncWorkflowsNamespaceProtocol /
AsyncWorkflowsNamespaceProtocol):
from typing import Any, Protocol
from imednet.plugins import SyncWorkflowsNamespaceProtocol
class PluginProtocol(Protocol):
def __call__(self, sdk_instance: Any) -> SyncWorkflowsNamespaceProtocol: ...
The built-in imednet-workflows package registers all nine workflows
symmetrically across imednet.workflows
(SyncWorkflowsNamespaceProtocol on ImednetSDK) and
imednet.async_workflows
(AsyncWorkflowsNamespaceProtocol on
AsyncImednetSDK), while imednet-sinks binds export_to_mongodb,
export_to_neo4j, and export_to_snowflake on both ImednetSDK.sinks
and AsyncImednetSDK.sinks:
data_extractionduckdb_centralizerquery_managementrecord_mapperrecord_updateregister_subjectssubject_datauatuat_inspector
Minimal working example¶
# myplugin/workflows.py
from __future__ import annotations
from typing import TYPE_CHECKING, Any
if TYPE_CHECKING:
from imednet.sdk import ImednetSDK
class MyDataExtraction:
def __init__(self, sdk: "ImednetSDK") -> None:
self._sdk = sdk
def run(self, study_key: str) -> list[Any]:
return list(self._sdk.records.list(study_key=study_key))
Registering the entry point¶
Add the following standard PEP 621 entry-point table to your package’s
pyproject.toml to register a workflow on sdk.workflows (or a namespace
plugin under imednet.plugins):
[project.entry-points."imednet.workflows"]
my_extraction = "myplugin.workflows:MyDataExtraction"
[project.entry-points."imednet.plugins"]
sinks = "imednet_sinks.plugin:create_sinks"
Or, when using setuptools, in setup.cfg:
[options.entry_points]
imednet.workflows =
my_extraction = myplugin.workflows:MyDataExtraction
imednet.plugins =
sinks = imednet_sinks.plugin:create_sinks
Once installed (e.g. pip install myplugin), the SDK discovers and
instantiates registered workflows automatically:
from imednet import ImednetSDK
sdk = ImednetSDK(api_key="...", security_key="...")
records = sdk.workflows.data_extraction.extract_records_by_criteria("MY_STUDY")
Error handling¶
PluginLoadError is raised when loading a namespace
plugin from imednet.plugins if:
More than one plugin is registered for the same entry-point name in the
imednet.pluginsgroup.The entry point fails to import (e.g. broken dependency).
The loaded object is not callable.
The factory raises
TypeErrorwhen called with the SDK instance.
PluginLoadError is a subclass of
ImednetError so it can be caught uniformly:
from imednet import ImednetSDK
from imednet.errors import ImednetError
try:
sdk = ImednetSDK(api_key="...", security_key="...")
except ImednetError as exc:
print(f"SDK initialisation failed: {exc}")
API reference¶
- class imednet.plugins.PluginProtocol[source]
Bases:
ProtocolProtocol that every iMednet plugin factory must satisfy.
A conforming factory is a callable that accepts an SDK instance and returns an object implementing
WorkflowsNamespaceProtocol.Example:
from imednet.plugins import PluginProtocol from imednet.sdk import ImednetSDK class MyWorkflows: def __init__(self, sdk: ImednetSDK) -> None: self.data_extraction = ... self.duckdb_centralizer = ... self.query_management = ... self.record_mapper = ... self.record_update = ... self.register_subjects = ... self.subject_data = ... self.uat = ... self.uat_inspector = ... def create_workflows(sdk: ImednetSDK) -> MyWorkflows: return MyWorkflows(sdk) # Verify conformance at import time (optional, for development use): assert isinstance(create_workflows, PluginProtocol)
- __call__(sdk_instance, /)[source]
Initialize the workflows plugin with an SDK instance.
- Parameters:
sdk_instance (ImednetFacade) –
- Return type:
- class imednet.plugins.SyncWorkflowsNamespaceProtocol[source]
Bases:
ProtocolSynchronous workflows namespace contract exposed on
ImednetSDK.workflows.- property data_extraction: DataExtractionWorkflowProtocol
Access the synchronous data extraction workflow.
- property duckdb_centralizer: DuckDBIngestionWorkflowProtocol
Access the lazy DuckDB bronze/silver ingestion workflow.
- property query_management: QueryManagementWorkflowProtocol
Access the query management workflow.
- property record_mapper: RecordMapperProtocol
Access the tabular and SDTM record mapper workflow.
- property record_update: SyncRecordUpdateWorkflowProtocol
Access the synchronous record submission and update workflow.
- property register_subjects: SyncRegisterSubjectsWorkflowProtocol
Access the synchronous bulk subject registration workflow.
- property subject_data: SubjectDataWorkflowProtocol
Access the comprehensive subject data retrieval workflow.
- property uat: UATWorkflowProtocol
Access the end-to-end UAT orchestration workflow.
- property uat_inspector: SyncStudySchemaInspectorProtocol
Access the synchronous study schema inspector.
- class imednet.plugins.AsyncWorkflowsNamespaceProtocol[source]
Bases:
ProtocolAsynchronous workflows namespace contract exposed on
AsyncImednetSDK.workflows.- property data_extraction: AsyncDataExtractionWorkflowProtocol
Access the asynchronous data extraction workflow.
- property duckdb_centralizer: AsyncDuckDBIngestionWorkflowProtocol
Access the asynchronous DuckDB bronze/silver ingestion workflow.
- property query_management: AsyncQueryManagementWorkflowProtocol
Access the asynchronous query management workflow.
- property record_mapper: AsyncRecordMapperProtocol
Access the asynchronous tabular and SDTM record mapper workflow.
- property record_update: AsyncRecordUpdateWorkflowProtocol
Access the asynchronous record submission and update workflow.
- property register_subjects: AsyncRegisterSubjectsWorkflowProtocol
Access the asynchronous bulk subject registration workflow.
- property subject_data: AsyncSubjectDataWorkflowProtocol
Access the asynchronous comprehensive subject data retrieval workflow.
- property uat: AsyncUATWorkflowProtocol
Access the asynchronous end-to-end UAT orchestration workflow.
- property uat_inspector: AsyncStudySchemaInspectorProtocol
Access the asynchronous study schema inspector.
- class imednet.plugins.SinksNamespaceProtocol[source]
Bases:
ProtocolSynchronous sinks namespace contract exposed on
ImednetSDK.sinks.- property MongoDbExportSink: MongoDbExportSinkFactoryProtocol
Sink class for MongoDB record exports.
- property MongoDbSinkConfig: MongoDbSinkConfigFactoryProtocol
Configuration class for MongoDB export sinks.
- property Neo4jExportSink: Neo4jExportSinkFactoryProtocol
Sink class for Neo4j record exports.
- property Neo4jSinkConfig: Neo4jSinkConfigFactoryProtocol
Configuration class for Neo4j export sinks.
- property SnowflakeExportSink: SnowflakeExportSinkFactoryProtocol
Sink class for Snowflake record exports.
- property SnowflakeSinkConfig: SnowflakeSinkConfigFactoryProtocol
Configuration class for Snowflake export sinks.
- property export_to_mongodb: BoundExportToMongoDbProtocol
Bound helper to export study records to MongoDB.
- property export_to_neo4j: BoundExportToNeo4jProtocol
Bound helper to export study records to Neo4j.
- property export_to_snowflake: BoundExportToSnowflakeProtocol
Bound helper to export study records to Snowflake.
- class imednet.plugins.AsyncSinksNamespaceProtocol[source]
Bases:
ProtocolAsynchronous sinks namespace contract exposed on
AsyncImednetSDK.sinks.- property AsyncMongoDbExportSink: AsyncMongoDbExportSinkFactoryProtocol
Asynchronous sink class for MongoDB record exports.
- property AsyncNeo4jExportSink: AsyncNeo4jExportSinkFactoryProtocol
Asynchronous sink class for Neo4j record exports.
- property AsyncSnowflakeExportSink: AsyncSnowflakeExportSinkFactoryProtocol
Asynchronous sink class for Snowflake record exports.
- property MongoDbExportSink: MongoDbExportSinkFactoryProtocol
Synchronous sink class for MongoDB record exports.
- property MongoDbSinkConfig: MongoDbSinkConfigFactoryProtocol
Configuration class for MongoDB export sinks.
- property Neo4jExportSink: Neo4jExportSinkFactoryProtocol
Synchronous sink class for Neo4j record exports.
- property Neo4jSinkConfig: Neo4jSinkConfigFactoryProtocol
Configuration class for Neo4j export sinks.
- property SnowflakeExportSink: SnowflakeExportSinkFactoryProtocol
Synchronous sink class for Snowflake record exports.
- property SnowflakeSinkConfig: SnowflakeSinkConfigFactoryProtocol
Configuration class for Snowflake export sinks.
- property export_to_mongodb: BoundAsyncExportToMongoDbProtocol
Bound coroutine helper to export study records to MongoDB.
- property export_to_neo4j: BoundAsyncExportToNeo4jProtocol
Bound coroutine helper to export study records to Neo4j.
- property export_to_snowflake: BoundAsyncExportToSnowflakeProtocol
Bound coroutine helper to export study records to Snowflake.
- exception imednet.errors.PluginLoadError[source]
Bases:
ImednetErrorRaised when a plugin fails to load or does not satisfy the
PluginProtocol.- __init__(message='', status_code=None, code=None, status=None, *, diagnostic_context=None)
Initialize the error.
- Parameters:
message (str) –
status_code (int | None) –
code (int | None) –
status (Any) –
diagnostic_context (DiagnosticContext | None) –
- Return type:
None
- property attempt_count: int | None
Return the number of attempts executed before failure, if present.
- property cause_type: str | None
Return the underlying exception class name, if present.
- property method: str | None
Return the HTTP method from
diagnostic_context, if present.
- property retry_after: float | None
Return the parsed
Retry-Afterdelay in seconds, if present.
- property url: str | None
Return the sanitized request URL from
diagnostic_context, if present.