imednet.spi package

Service Provider Interface (SPI) for Imednet Extensions.

This module provides a stable public interface for advanced platform developers, plugins, and providers, decoupling them from internal core implementation details.

Submodules

imednet.spi.cdisc module

SPI for CDISC ODM 1.3.2 and Dataset-JSON v1.1 exchange models, builders, and validators.

imednet.spi.cli module

Service Provider Interface (SPI) for CLI extensions.

imednet.spi.constants module

SPI for constants.

imednet.spi.endpoints module

SPI for endpoints.

imednet.spi.errors module

SPI for error types.

imednet.spi.facade module

Facade protocols for the iMednet SDK.

These protocols define the expected interface for the iMednet SDK clients, allowing for easier mocking and decoupling in dependent packages.

class imednet.spi.facade.AsyncImednetFacade[source]

Bases: Protocol

Protocol for the asynchronous iMednet SDK facade.

property auth: AuthStrategy | None

Access the authentication provider for the asynchronous facade.

async create_record(study_key, records_data, email_notify=None, *, schema=None, skip_validation=False)[source]

Asynchronously submit a request to create one or more data records.

Parameters:
  • study_key (str) – The unique identifier for the study.

  • records_data (Sequence[BaseRecordRequest | Mapping[str, Any]] | DataFrameLike | str | PathLike[str]) – Record dicts, a pandas DataFrame, or a CSV file path.

  • email_notify (bool | str | None) – Optional email notification settings.

  • schema (ValidationSchemaProtocol | None) – Optional validation schema.

  • skip_validation (bool) – Optional flag to skip validation when pre-validated.

Returns:

A Job model representing the background operation.

Return type:

Job

async create_records_batch(study_key, records_data, email_notify=None, *, schema=None, chunk_size=100, skip_validation=False, wait_for_completion=False, timeout=300.0, interval=5.0, on_progress=None, dry_run=False, collect_errors=False, resolve_results=True)[source]

Asynchronously submit records in bounded chunks with optional multi-job polling.

Parameters:
  • study_key (str) –

  • records_data (Sequence[BaseRecordRequest | Mapping[str, Any]] | DataFrameLike | str | PathLike[str]) –

  • email_notify (bool | str | None) –

  • schema (ValidationSchemaProtocol | None) –

  • chunk_size (int) –

  • skip_validation (bool) –

  • wait_for_completion (bool) –

  • timeout (float) –

  • interval (float) –

  • on_progress (JobProgressCallback | Callable[[JobStatusEvent], None] | None) –

  • dry_run (bool) –

  • collect_errors (bool) –

  • resolve_results (bool) –

Return type:

BatchSubmissionSummary

async get_codings(study_key=None, **filters)[source]

Asynchronously fetch code list definitions for a specific study.

Parameters:
  • study_key (str | None) – The unique identifier for the study.

  • **filters (str | int | float | bool | tuple[str, str | int | float | bool | None] | list[tuple[str, str | int | float | bool | None]] | list[str | int | float | bool | None] | None) – Optional API filters to apply.

Returns:

A list of Coding models.

Return type:

list[Coding]

async get_forms(study_key=None, **filters)[source]

Asynchronously fetch form definitions for a specific study.

Parameters:
  • study_key (str | None) – The unique identifier for the study.

  • **filters (str | int | float | bool | tuple[str, str | int | float | bool | None] | list[tuple[str, str | int | float | bool | None]] | list[str | int | float | bool | None] | None) – Optional API filters to apply.

Returns:

A list of Form models.

Return type:

list[Form]

async get_intervals(study_key=None, **filters)[source]

Asynchronously fetch visit interval definitions for a specific study.

Parameters:
  • study_key (str | None) – The unique identifier for the study.

  • **filters (str | int | float | bool | tuple[str, str | int | float | bool | None] | list[tuple[str, str | int | float | bool | None]] | list[str | int | float | bool | None] | None) – Optional API filters to apply.

Returns:

A list of Interval models.

Return type:

list[Interval]

async get_job(study_key, batch_id)[source]

Asynchronously fetch the status of a specific background job.

Parameters:
  • study_key (str) – The unique identifier for the study.

  • batch_id (str) – The unique identifier for the job batch.

Returns:

A JobStatus model.

Return type:

JobStatus

async get_queries(study_key=None, **filters)[source]

Asynchronously fetch queries for a specific study.

Parameters:
  • study_key (str | None) – The unique identifier for the study.

  • **filters (str | int | float | bool | tuple[str, str | int | float | bool | None] | list[tuple[str, str | int | float | bool | None]] | list[str | int | float | bool | None] | None) – Optional API filters to apply.

Returns:

A list of Query models.

Return type:

list[Query]

async get_record_revisions(study_key=None, **filters)[source]

Asynchronously fetch record revision history for a specific study.

Parameters:
  • study_key (str | None) – The unique identifier for the study.

  • **filters (str | int | float | bool | tuple[str, str | int | float | bool | None] | list[tuple[str, str | int | float | bool | None]] | list[str | int | float | bool | None] | None) – Optional API filters to apply.

Returns:

A list of RecordRevision models.

Return type:

list[RecordRevision]

async get_records(study_key=None, **filters)[source]

Asynchronously fetch data records for a specific study.

Parameters:
  • study_key (str | None) – The unique identifier for the study.

  • **filters (str | int | float | bool | tuple[str, str | int | float | bool | None] | list[tuple[str, str | int | float | bool | None]] | list[str | int | float | bool | None] | None) – Optional API filters to apply.

Returns:

A list of Record models.

Return type:

list[Record]

async get_sites(study_key=None, **filters)[source]

Asynchronously fetch site definitions for a specific study.

Parameters:
  • study_key (str | None) – The unique identifier for the study.

  • **filters (str | int | float | bool | tuple[str, str | int | float | bool | None] | list[tuple[str, str | int | float | bool | None]] | list[str | int | float | bool | None] | None) – Optional API filters to apply.

Returns:

A list of Site models.

Return type:

list[Site]

async get_studies(**filters)[source]

Asynchronously fetch all studies accessible to the current user.

Parameters:

**filters (str | int | float | bool | tuple[str, str | int | float | bool | None] | list[tuple[str, str | int | float | bool | None]] | list[str | int | float | bool | None] | None) – Optional API filters to apply.

Returns:

A list of Study models.

Return type:

list[Study]

async get_subjects(study_key=None, **filters)[source]

Asynchronously fetch subject records for a specific study.

Parameters:
  • study_key (str | None) – The unique identifier for the study.

  • **filters (str | int | float | bool | tuple[str, str | int | float | bool | None] | list[tuple[str, str | int | float | bool | None]] | list[str | int | float | bool | None] | None) – Optional API filters to apply.

Returns:

A list of Subject models.

Return type:

list[Subject]

async get_users(study_key=None, **filters)[source]

Asynchronously fetch user definitions for a specific study.

Parameters:
  • study_key (str | None) – The unique identifier for the study.

  • **filters (str | int | float | bool | tuple[str, str | int | float | bool | None] | list[tuple[str, str | int | float | bool | None]] | list[str | int | float | bool | None] | None) – Optional API filters to apply.

Returns:

A list of User models.

Return type:

list[User]

async get_variables(study_key=None, **filters)[source]

Asynchronously fetch variable definitions for a specific study.

Parameters:
  • study_key (str | None) – The unique identifier for the study.

  • **filters (str | int | float | bool | tuple[str, str | int | float | bool | None] | list[tuple[str, str | int | float | bool | None]] | list[str | int | float | bool | None] | None) – Optional API filters to apply.

Returns:

A list of Variable models.

Return type:

list[Variable]

async get_visits(study_key=None, **filters)[source]

Asynchronously fetch visit definitions for a specific study.

Parameters:
  • study_key (str | None) – The unique identifier for the study.

  • **filters (str | int | float | bool | tuple[str, str | int | float | bool | None] | list[tuple[str, str | int | float | bool | None]] | list[str | int | float | bool | None] | None) – Optional API filters to apply.

Returns:

A list of Visit models.

Return type:

list[Visit]

async poll_job(study_key, batch_id, *, interval=5, timeout=300, on_progress=None, resolve_results=False)[source]

Asynchronously wait for a background job to reach a terminal state.

Parameters:
  • study_key (str) – The unique identifier for the study.

  • batch_id (str) – The unique identifier for the job batch.

  • interval (float) – Time between poll attempts in seconds.

  • timeout (float) – Maximum time to wait in seconds.

  • on_progress (JobProgressCallback | Callable[[JobStatusEvent], None] | None) – Optional callback invoked on each poll cycle.

  • resolve_results (bool) – Whether to fetch and validate terminal resultUrl payloads.

Returns:

The final JobStatus of the operation.

Return type:

JobStatus

async poll_jobs(study_key, batch_ids, *, interval=5.0, timeout=300.0, on_progress=None, fail_fast=False, resolve_results=False)[source]

Asynchronously wait for multiple background jobs, optionally resolving resultUrl payloads.

Parameters:
  • study_key (str) –

  • batch_ids (list[str]) –

  • interval (float) –

  • timeout (float) –

  • on_progress (JobProgressCallback | Callable[[JobStatusEvent], None] | None) –

  • fail_fast (bool) –

  • resolve_results (bool) –

Return type:

JobPollSummary

study_context(study_key)[source]

Bind a study key to this facade instance for the duration of the with-block.

Parameters:

study_key (str) –

Return type:

AbstractContextManager[Self]

class imednet.spi.facade.ImednetFacade[source]

Bases: Protocol

Protocol for the synchronous iMednet SDK facade.

property auth: AuthStrategy | None

Access the authentication provider for the facade.

create_record(study_key, records_data, email_notify=None, *, schema=None, skip_validation=False)[source]

Submit a request to create one or more data records.

Parameters:
  • study_key (str) – The unique identifier for the study.

  • records_data (Sequence[BaseRecordRequest | Mapping[str, Any]] | DataFrameLike | str | PathLike[str]) – Record dicts, a pandas DataFrame, or a CSV file path.

  • email_notify (bool | str | None) – Optional email notification settings.

  • schema (ValidationSchemaProtocol | None) – Optional validation schema.

  • skip_validation (bool) – Optional flag to skip validation when pre-validated.

Returns:

A Job model representing the background operation.

Return type:

Job

create_records_batch(study_key, records_data, email_notify=None, *, schema=None, chunk_size=100, skip_validation=False, wait_for_completion=False, timeout=300.0, interval=5.0, on_progress=None, dry_run=False, collect_errors=False, resolve_results=True)[source]

Submit records in bounded chunks with optional multi-job polling.

Parameters:
  • study_key (str) –

  • records_data (Sequence[BaseRecordRequest | Mapping[str, Any]] | DataFrameLike | str | PathLike[str]) –

  • email_notify (bool | str | None) –

  • schema (ValidationSchemaProtocol | None) –

  • chunk_size (int) –

  • skip_validation (bool) –

  • wait_for_completion (bool) –

  • timeout (float) –

  • interval (float) –

  • on_progress (JobProgressCallback | Callable[[JobStatusEvent], None] | None) –

  • dry_run (bool) –

  • collect_errors (bool) –

  • resolve_results (bool) –

Return type:

BatchSubmissionSummary

get_codings(study_key=None, **filters)[source]

Fetch code list definitions for a specific study.

Parameters:
  • study_key (str | None) – The unique identifier for the study.

  • **filters (str | int | float | bool | tuple[str, str | int | float | bool | None] | list[tuple[str, str | int | float | bool | None]] | list[str | int | float | bool | None] | None) – Optional API filters to apply.

Returns:

A list of Coding models.

Return type:

list[Coding]

get_forms(study_key=None, **filters)[source]

Fetch form definitions for a specific study.

Parameters:
  • study_key (str | None) – The unique identifier for the study.

  • **filters (str | int | float | bool | tuple[str, str | int | float | bool | None] | list[tuple[str, str | int | float | bool | None]] | list[str | int | float | bool | None] | None) – Optional API filters to apply.

Returns:

A list of Form models.

Return type:

list[Form]

get_intervals(study_key=None, **filters)[source]

Fetch visit interval definitions for a specific study.

Parameters:
  • study_key (str | None) – The unique identifier for the study.

  • **filters (str | int | float | bool | tuple[str, str | int | float | bool | None] | list[tuple[str, str | int | float | bool | None]] | list[str | int | float | bool | None] | None) – Optional API filters to apply.

Returns:

A list of Interval models.

Return type:

list[Interval]

get_job(study_key, batch_id)[source]

Fetch the status of a specific background job.

Parameters:
  • study_key (str) – The unique identifier for the study.

  • batch_id (str) – The unique identifier for the job batch.

Returns:

A JobStatus model.

Return type:

JobStatus

get_queries(study_key=None, **filters)[source]

Fetch queries for a specific study.

Parameters:
  • study_key (str | None) – The unique identifier for the study.

  • **filters (str | int | float | bool | tuple[str, str | int | float | bool | None] | list[tuple[str, str | int | float | bool | None]] | list[str | int | float | bool | None] | None) – Optional API filters to apply.

Returns:

A list of Query models.

Return type:

list[Query]

get_record_revisions(study_key=None, **filters)[source]

Fetch record revision history for a specific study.

Parameters:
  • study_key (str | None) – The unique identifier for the study.

  • **filters (str | int | float | bool | tuple[str, str | int | float | bool | None] | list[tuple[str, str | int | float | bool | None]] | list[str | int | float | bool | None] | None) – Optional API filters to apply.

Returns:

A list of RecordRevision models.

Return type:

list[RecordRevision]

get_records(study_key=None, **filters)[source]

Fetch data records for a specific study.

Parameters:
  • study_key (str | None) – The unique identifier for the study.

  • **filters (str | int | float | bool | tuple[str, str | int | float | bool | None] | list[tuple[str, str | int | float | bool | None]] | list[str | int | float | bool | None] | None) – Optional API filters to apply.

Returns:

A list of Record models.

Return type:

list[Record]

get_sites(study_key=None, **filters)[source]

Fetch site definitions for a specific study.

Parameters:
  • study_key (str | None) – The unique identifier for the study.

  • **filters (str | int | float | bool | tuple[str, str | int | float | bool | None] | list[tuple[str, str | int | float | bool | None]] | list[str | int | float | bool | None] | None) – Optional API filters to apply.

Returns:

A list of Site models.

Return type:

list[Site]

get_studies(**filters)[source]

Fetch all studies accessible to the current user.

Parameters:

**filters (str | int | float | bool | tuple[str, str | int | float | bool | None] | list[tuple[str, str | int | float | bool | None]] | list[str | int | float | bool | None] | None) – Optional API filters to apply.

Returns:

A list of Study models.

Return type:

list[Study]

get_subjects(study_key=None, **filters)[source]

Fetch subject records for a specific study.

Parameters:
  • study_key (str | None) – The unique identifier for the study.

  • **filters (str | int | float | bool | tuple[str, str | int | float | bool | None] | list[tuple[str, str | int | float | bool | None]] | list[str | int | float | bool | None] | None) – Optional API filters to apply.

Returns:

A list of Subject models.

Return type:

list[Subject]

get_users(study_key=None, **filters)[source]

Fetch user definitions for a specific study.

Parameters:
  • study_key (str | None) – The unique identifier for the study.

  • **filters (str | int | float | bool | tuple[str, str | int | float | bool | None] | list[tuple[str, str | int | float | bool | None]] | list[str | int | float | bool | None] | None) – Optional API filters to apply.

Returns:

A list of User models.

Return type:

list[User]

get_variables(study_key=None, **filters)[source]

Fetch variable definitions for a specific study.

Parameters:
  • study_key (str | None) – The unique identifier for the study.

  • **filters (str | int | float | bool | tuple[str, str | int | float | bool | None] | list[tuple[str, str | int | float | bool | None]] | list[str | int | float | bool | None] | None) – Optional API filters to apply.

Returns:

A list of Variable models.

Return type:

list[Variable]

get_visits(study_key=None, **filters)[source]

Fetch visit definitions for a specific study.

Parameters:
  • study_key (str | None) – The unique identifier for the study.

  • **filters (str | int | float | bool | tuple[str, str | int | float | bool | None] | list[tuple[str, str | int | float | bool | None]] | list[str | int | float | bool | None] | None) – Optional API filters to apply.

Returns:

A list of Visit models.

Return type:

list[Visit]

poll_job(study_key, batch_id, *, interval=5, timeout=300, on_progress=None, resolve_results=False)[source]

Wait for a background job to reach a terminal state.

Parameters:
  • study_key (str) – The unique identifier for the study.

  • batch_id (str) – The unique identifier for the job batch.

  • interval (float) – Time between poll attempts in seconds.

  • timeout (float) – Maximum time to wait in seconds.

  • on_progress (JobProgressCallback | Callable[[JobStatusEvent], None] | None) – Optional callback invoked on each poll cycle.

  • resolve_results (bool) – Whether to fetch and validate terminal resultUrl payloads.

Returns:

The final JobStatus of the operation.

Return type:

JobStatus

poll_jobs(study_key, batch_ids, *, interval=5.0, timeout=300.0, on_progress=None, fail_fast=False, resolve_results=False)[source]

Wait for multiple background jobs concurrently, optionally resolving resultUrl payloads.

Parameters:
  • study_key (str) –

  • batch_ids (list[str]) –

  • interval (float) –

  • timeout (float) –

  • on_progress (JobProgressCallback | Callable[[JobStatusEvent], None] | None) –

  • fail_fast (bool) –

  • resolve_results (bool) –

Return type:

JobPollSummary

study_context(study_key)[source]

Bind a study key to this facade instance for the duration of the with-block.

Parameters:

study_key (str) –

Return type:

AbstractContextManager[Self]

imednet.spi.models module

SPI for models.

imednet.spi.sink_base module

Public Service Provider Interface for export sinks.

Provides base classes and utilities for external export sink implementations, decoupling them from internal integration components.

imednet.spi.sink_base.normalize_watermark_datetime(value)[source]

Normalize a datetime or ISO-8601 date/timestamp string into UTC.

Parameters:

value (datetime | str | None) –

Return type:

datetime | None

imednet.spi.sinks module

Supported core capabilities for external export sink implementations.

imednet.spi.sinks.build_sink_mapper(config, *, mode='document', post_processor=None, seq_counters=None, domain_seq_counters=None, form_domain_map=None, seq_overrides=None, lineage_out=None, record_seqs=None, preserve_record_id=None, lineage_session=None)[source]

Create a CentralizedMapper configured with SinkConfig PHI, SDTM, and naming rules.

Parameters:
  • config (SinkConfig) –

  • mode (str) –

  • post_processor (Callable[[dict[str, Any]], dict[str, Any]] | None) –

  • seq_counters (dict[str, int] | None) –

  • domain_seq_counters (dict[str, dict[str, int]] | None) –

  • form_domain_map (Mapping[Any, str] | None) –

  • seq_overrides (Mapping[str, int] | None) –

  • lineage_out (dict[str, dict[str, Any]] | None) –

  • record_seqs (dict[str, int] | None) –

  • preserve_record_id (bool | None) –

  • lineage_session (SdtmLineageSession | None) –

Return type:

CentralizedMapper

imednet.spi.sinks.redact_uri(uri)[source]

Return a destination URI with credentials masked.

Parameters:

uri (str) –

Return type:

str

imednet.spi.sinks.require_optional_dep(module_name, extra)[source]

Load a destination driver or raise the existing actionable install error.

Parameters:
  • module_name (str) –

  • extra (str) –

Return type:

Any

imednet.spi.utils module

SPI for utility functions.

imednet.spi.utils.delegates_to_sdk_retry_policy(sdk, target_callable=None)[source]

Return True when sdk executes HTTP calls through a sync client with DefaultRetryPolicy.

Parameters:
  • sdk (Any) –

  • target_callable (Any) –

Return type:

bool

imednet.spi.utils.extract_record_errors(status, *, registry=None)[source]

Extract sanitized per-record and variable-level error entries from a JobStatus.

Parameters:
  • status (JobStatus | Any) –

  • registry (Any) –

Return type:

list[dict[str, Any]]

imednet.spi.utils.extract_sdk_base_url(sdk)[source]

Extract a normalized string base URL from an SDK or client instance, if present.

Parameters:

sdk (Any) –

Return type:

str | None

imednet.spi.utils.extract_sdk_security_key(sdk)[source]

Extract a non-empty governance secret from an SDK or client instance, if present.

Precedence follows ADR-0005 when explicit encryption env vars are unset: explicit/configured security_key, then OIDC bearer token, then api_key.

Parameters:

sdk (Any) –

Return type:

str | None

async imednet.spi.utils.fetch_terminal_job_result_async(status, fetch_result, *, batch_id=None)[source]

Asynchronously fetch and attach resultUrl output for a terminal Job status.

Parameters:
  • status (JobStatus | Any) –

  • fetch_result (Callable[[str], Awaitable[Any]] | None) –

  • batch_id (str | None) –

Return type:

JobStatus | Any

imednet.spi.utils.format_record_error_item_detail(sanitized_item, *, registry=None)[source]

Extract sanitized variable-level and record-level error detail strings from an item.

Parameters:
  • sanitized_item (Any) –

  • registry (Any) –

Return type:

list[str]

imednet.spi.utils.format_record_error_line(item, *, index=1, registry=None, preserve_ident_keys=False)[source]

Format a single sanitized Record (...): detail summary line from a record error entry.

Parameters:
  • item (Any) –

  • index (int) –

  • registry (Any) –

  • preserve_ident_keys (bool) –

Return type:

str

imednet.spi.utils.get_base_url_context()[source]

Get the current base URL for the active thread/task context.

Return type:

str | None

imednet.spi.utils.get_security_key_context()[source]

Get the current SDK security key for the active thread/task context.

Return type:

str | None

imednet.spi.utils.get_study_context()[source]

Get the current study key for the active thread/task context.

Return type:

str | None

imednet.spi.utils.is_fetchable_result_url(url)[source]

Return True when resultUrl is a non-empty, non-placeholder string.

Parameters:

url (Any) –

Return type:

bool

imednet.spi.utils.job_item_has_error(item)[source]

Return True when a job result item reports record-level or variable-level errors.

Parameters:

item (dict[str, Any]) –

Return type:

bool

imednet.spi.utils.matches_revision_date_bound(rev_dt, op, bound_val, *, attr_name='dateCreated')[source]

Evaluate a local date comparison operator against a parsed UTC timestamp.

Parameters:
  • rev_dt (datetime | None) –

  • op (str) –

  • bound_val (Any) –

  • attr_name (str) –

Return type:

bool

imednet.spi.utils.matches_revision_date_bounds(item, local_bounds)[source]

Return True if item satisfies all (snake_attr, op, bound_val) local date bounds.

Parameters:
  • item (Any) –

  • local_bounds (Sequence[tuple[str, str, Any]]) –

Return type:

bool

imednet.spi.utils.parse_revision_timestamp_utc(raw)[source]

Parse a revision timestamp or date into a UTC-aware datetime.

Parameters:

raw (Any) –

Return type:

datetime | None

imednet.spi.utils.reset_base_url_context(token)[source]

Reset the active base URL using a token from set_base_url_context().

Parameters:

token (Token[str | None]) –

Return type:

None

imednet.spi.utils.reset_security_key_context(token)[source]

Reset the active SDK security key using a token from set_security_key_context().

Parameters:

token (Token[str | None]) –

Return type:

None

imednet.spi.utils.resolve_async_sdk_result_fetcher(sdk)[source]

Resolve an asynchronous resultUrl fetcher callable from an async SDK or endpoint double.

Parameters:

sdk (Any) –

Return type:

Callable[[str], Awaitable[Any]] | None

imednet.spi.utils.sdk_governance_context(sdk)[source]

Bind normalized base_url and security_key context from sdk for the block.

Parameters:

sdk (Any) –

Return type:

Iterator[None]

imednet.spi.utils.security_key_context(security_key)[source]

Temporarily set the active SDK security key for the current thread/task context.

Parameters:

security_key (str | None) –

Return type:

Iterator[None]

imednet.spi.utils.set_base_url_context(base_url)[source]

Set the active base URL for the current thread/task context.

Parameters:

base_url (str) –

Return type:

Token[str | None]

imednet.spi.utils.set_security_key_context(security_key)[source]

Set the active SDK security key for the current thread/task context.

Parameters:

security_key (str | None) –

Return type:

Token[str | None]

imednet.spi.utils.split_revision_date_bounds(filters, *, start_date=None, end_date=None)[source]

Split secondary dateCreated and lastUpdated AND bounds for local evaluation.

Ensures upstream requests contain at most one dateCreated clause and at most one lastUpdated clause per AND filter while evaluating all remaining date bounds locally.

Parameters:
  • filters (Mapping[str, Any]) –

  • start_date (str | datetime | date | None) –

  • end_date (str | datetime | date | None) –

Return type:

tuple[dict[str, Any], list[tuple[str, str, Any]]]

imednet.spi.validation module

SPI for validation utilities.