imednet.core package

Re-exports core components for easier access.

class imednet.core.AsyncClient[source]

Bases: HTTPClientBase

Asynchronous variant of Client.

__init__(api_key=None, security_key=None, base_url=None, timeout=None, tracer=None, retry_config=None, auth=None, transport=None, simulation_mode=None, *, config=None, oidc_token=None, strict_mode=None, credential_source=None)

Initialize the HTTP client and request executor.

Parameters:
  • api_key (str | None) –

  • security_key (str | None) –

  • base_url (str | None) –

  • timeout (float | Timeout | None) –

  • tracer (Any | None) –

  • retry_config (RetryConfig | None) –

  • auth (AuthStrategy | None) –

  • transport (BaseTransport | AsyncBaseTransport | None) –

  • simulation_mode (bool | None) –

  • config (Config | None) –

  • oidc_token (str | None) –

  • strict_mode (bool | None) –

  • credential_source (CredentialSource | None) –

Return type:

None

async aclose()[source]

Close the underlying async HTTP client.

Return type:

None

async fetch_external_url(url, **kwargs)[source]

Asynchronously fetch an external HTTPS URL with SSRF and redirect protections.

Parameters:
  • url (str) –

  • kwargs (Any) –

Return type:

Response

async get(path, params=None, **kwargs)[source]

Make an asynchronous GET request.

Parameters:
  • path (str) – URL path or full URL.

  • params (dict[str, Any] | None) – Query parameters.

  • **kwargs (Any) – Additional arguments passed to the underlying executor.

Return type:

Response

async post(path, json=None, **kwargs)[source]

Make an asynchronous POST request.

Parameters:
  • path (str) – URL path or full URL.

  • json (Any | None) – JSON body for the request.

  • **kwargs (Any) – Additional arguments passed to the underlying executor.

Return type:

Response

property retry_policy: RetryPolicy

Return the current retry policy of the executor.

class imednet.core.BaseClient[source]

Bases: object

Common initialization logic for HTTP clients.

__init__(api_key=None, security_key=None, base_url=None, timeout=None, tracer=None, retry_config=None, auth=None, transport=None, simulation_mode=None, *, config=None, oidc_token=None, strict_mode=None, credential_source=None)[source]

Initialize common client settings.

Parameters:
  • api_key (str | None) – iMednet API key.

  • security_key (str | None) – iMednet security key.

  • base_url (str | None) – Base URL for the iMednet API.

  • timeout (float | Timeout | None) – Default request timeout in seconds or httpx.Timeout.

  • tracer (Any | None) – Optional OpenTelemetry tracer instance.

  • retry_config (RetryConfig | None) – Centralized configuration for retry behaviors.

  • auth (AuthStrategy | None) – Optional pre-configured AuthStrategy.

  • transport (BaseTransport | AsyncBaseTransport | None) – Optional custom httpx transport (e.g. for simulation).

  • simulation_mode (bool | None) – Optional flag to enable offline simulation mode.

  • config (Config | None) – Optional pre-resolved Config instance.

  • oidc_token (str | None) – Optional explicit OIDC bearer token.

  • strict_mode (bool | None) – Optional strict validation mode override.

  • credential_source (CredentialSource | None) – Optional caller-owned credential source.

Return type:

None

class imednet.core.BasePaginator[source]

Bases: Generic[ClientT]

Shared paginator implementation.

__init__(client, path, params=None, page_size=100, page_param='page', size_param='size', data_key='data', metadata_key='metadata')[source]

Initialize the paginator.

Parameters:
  • client (ClientT) – Requester instance (sync or async).

  • path (str) – API path for the request.

  • params (dict[str, Any] | None) – Query parameters.

  • page_size (int) – Number of items per page (1 to 500).

  • page_param (str) – Query parameter name for the page index.

  • size_param (str) – Query parameter name for the page size.

  • data_key (str) – Key in the response JSON containing the items list.

  • metadata_key (str) – Key in the response JSON containing pagination metadata.

Return type:

None

property cursor: int | None

The next page cursor (0-based page index), or None before start and when exhausted.

property has_more: bool

Return True before iteration starts or while unconsumed items/pages remain.

page_size: int

Active number of items requested per page.

class imednet.core.Client[source]

Bases: HTTPClientBase

Core HTTP client for the iMednet API.

base_url

Base URL for API requests.

timeout

Default timeout for requests.

retry_config

Centralized configuration for retry behaviors.

__init__(api_key=None, security_key=None, base_url=None, timeout=None, tracer=None, retry_config=None, auth=None, transport=None, simulation_mode=None, *, config=None, oidc_token=None, strict_mode=None, credential_source=None)

Initialize the HTTP client and request executor.

Parameters:
  • api_key (str | None) –

  • security_key (str | None) –

  • base_url (str | None) –

  • timeout (float | Timeout | None) –

  • tracer (Any | None) –

  • retry_config (RetryConfig | None) –

  • auth (AuthStrategy | None) –

  • transport (BaseTransport | AsyncBaseTransport | None) –

  • simulation_mode (bool | None) –

  • config (Config | None) –

  • oidc_token (str | None) –

  • strict_mode (bool | None) –

  • credential_source (CredentialSource | None) –

Return type:

None

close()[source]

Close the underlying HTTP client.

Return type:

None

fetch_external_url(url, **kwargs)[source]

Fetch an external HTTPS URL with SSRF, origin-scoped auth, and redirect guards.

Parameters:
  • url (str) –

  • kwargs (Any) –

Return type:

Response

get(path, params=None, **kwargs)[source]

Make a GET request.

Parameters:
  • path (str) – URL path or full URL.

  • params (dict[str, Any] | None) – Query parameters.

  • **kwargs (Any) – Additional arguments passed to the underlying executor.

Return type:

Response

post(path, json=None, **kwargs)[source]

Make a POST request.

Parameters:
  • path (str) – URL path or full URL.

  • json (Any | None) – JSON body for the request.

  • **kwargs (Any) – Additional arguments passed to the underlying executor.

Return type:

Response

property retry_policy: RetryPolicy

Return the current retry policy of the executor.

class imednet.core.DefaultRetryPolicy[source]

Bases: object

Retry policy with idempotency-aware retry logic.

  • Network errors (httpx.RequestError), request timeouts (HTTP 408), and server errors (HTTP 500-599) are only retried for idempotent HTTP methods: GET, PUT, DELETE, HEAD, and OPTIONS.

  • Rate-limit responses (HTTP 429) are retried for all methods because the server rejected the request before processing the payload, so there is no risk of duplicate side-effects.

  • Requests with an unknown or missing method are treated as non-idempotent (fail-safe default): they are not retried on network errors, 408, or 5xx responses.

Overriding this behaviour

If you need retries on a POST endpoint that is internally deduplicated (e.g. the server uses an idempotency key), subclass RetryPolicy and pass an instance to the client:

from imednet.core.retry import RetryPolicy, RetryState, IDEMPOTENT_METHODS
import httpx

class IdempotentPostPolicy(RetryPolicy):
    def should_retry(self, state: RetryState) -> bool:
        method = (state.method or "").upper()
        if state.exception:
            return isinstance(state.exception, httpx.RequestError)
        response = state.result
        if isinstance(response, httpx.Response):
            return (
                response.status_code == 429
                or 500 <= response.status_code < 600
            )
        return False

sdk = ImednetSDK(..., retry_config=RetryConfig(retry_policy=IdempotentPostPolicy()))
should_retry(state)[source]

Return True if the request should be retried based on the state.

Parameters:

state (RetryState) –

Return type:

bool

class imednet.core.EdcAsyncGetEndpoint[source]

Bases: Generic[T]

Async EDC get-only endpoint base.

abstract property MODEL: type[T]

The model class associated with this endpoint.

abstract property PATH: str

The relative path for the endpoint.

__init__(async_client)

Initialize the asynchronous endpoint.

Parameters:

async_client (AsyncRequesterProtocol) –

Return type:

None

async get(study_key, item_id)

Retrieve a single resource by its ID.

Parameters:
  • study_key (str | None) – The study key.

  • item_id (str | int) – The ID of the resource to retrieve.

Returns:

The requested resource.

Return type:

T

requires_study_key: bool = True

Whether this endpoint requires a study key. Defaults to True. Override in subclasses if needed.

class imednet.core.EdcAsyncListEndpoint[source]

Bases: Generic[T]

Async EDC list-only endpoint base.

ASYNC_PAGINATOR_CLS

alias of AsyncPaginator

abstract property MODEL: type[T]

The model class associated with this endpoint.

PAGINATOR_CLS

alias of Paginator

abstract property PATH: str

The relative path for the endpoint.

__init__(async_client)

Initialize the asynchronous endpoint.

Parameters:

async_client (AsyncRequesterProtocol) –

Return type:

None

list(study_key=None, **filters)

List resources matching the given filters.

Parameters:
  • study_key (str | None) – Optional study key to override the default.

  • **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) – Resource filters.

Returns:

An iterator over the matching resources.

Return type:

AsyncIterator[T]

requires_study_key: bool = True

Whether this endpoint requires a study key. Defaults to True. Override in subclasses if needed.

async to_dataframe(study_key=None, *, mask_phi=True, **filters)[source]

Export queried resources asynchronously directly to a pandas DataFrame.

Parameters:
  • study_key (str | None) – Optional study key override.

  • mask_phi (bool) – Whether to mask sensitive PHI fields by default.

  • **filters (Any) – Resource filters passed to list().

Returns:

A pandas DataFrame containing the queried resources.

Raises:

ImportError – If pandas is not installed.

Return type:

DataFrame

class imednet.core.EdcAsyncListGetEndpoint[source]

Bases: EdcAsyncListEndpoint[T]

Async EDC list/get endpoint base.

ASYNC_PAGINATOR_CLS

alias of AsyncPaginator

abstract property MODEL: type[T]

The model class associated with this endpoint.

PAGINATOR_CLS

alias of Paginator

abstract property PATH: str

The relative path for the endpoint.

__init__(async_client)

Initialize the asynchronous endpoint.

Parameters:

async_client (AsyncRequesterProtocol) –

Return type:

None

async get(study_key, item_id)

Retrieve a single resource by its ID.

Parameters:
  • study_key (str | None) – The study key.

  • item_id (int) – The ID of the resource to retrieve.

Returns:

The requested resource.

Return type:

T

list(study_key=None, **filters)

List resources matching the given filters.

Parameters:
  • study_key (str | None) – Optional study key to override the default.

  • **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) – Resource filters.

Returns:

An iterator over the matching resources.

Return type:

AsyncIterator[T]

requires_study_key: bool = True

Whether this endpoint requires a study key. Defaults to True. Override in subclasses if needed.

async to_dataframe(study_key=None, *, mask_phi=True, **filters)

Export queried resources asynchronously directly to a pandas DataFrame.

Parameters:
  • study_key (str | None) – Optional study key override.

  • mask_phi (bool) – Whether to mask sensitive PHI fields by default.

  • **filters (Any) – Resource filters passed to list().

Returns:

A pandas DataFrame containing the queried resources.

Raises:

ImportError – If pandas is not installed.

Return type:

DataFrame

class imednet.core.EdcSyncGetEndpoint[source]

Bases: Generic[T]

Sync EDC get-only endpoint base.

abstract property MODEL: type[T]

The model class associated with this endpoint.

abstract property PATH: str

The relative path for the endpoint.

__init__(client)

Initialize the synchronous endpoint.

Parameters:

client (RequesterProtocol) –

Return type:

None

get(study_key, item_id)

Retrieve a single resource by its ID.

Parameters:
  • study_key (str | None) – The study key.

  • item_id (str | int) – The ID of the resource to retrieve.

Returns:

The requested resource.

Return type:

T

requires_study_key: bool = True

Whether this endpoint requires a study key. Defaults to True. Override in subclasses if needed.

class imednet.core.EdcSyncListEndpoint[source]

Bases: Generic[T]

Sync EDC list-only endpoint base.

ASYNC_PAGINATOR_CLS

alias of AsyncPaginator

abstract property MODEL: type[T]

The model class associated with this endpoint.

PAGINATOR_CLS

alias of Paginator

abstract property PATH: str

The relative path for the endpoint.

__init__(client)

Initialize the synchronous endpoint.

Parameters:

client (RequesterProtocol) –

Return type:

None

list(study_key=None, **filters)

List resources matching the given filters.

Parameters:
  • study_key (str | None) – Optional study key to override the default.

  • **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) – Resource filters.

Returns:

An iterator over the matching resources.

Return type:

Iterator[T]

requires_study_key: bool = True

Whether this endpoint requires a study key. Defaults to True. Override in subclasses if needed.

to_dataframe(study_key=None, *, mask_phi=True, **filters)[source]

Export queried resources directly to a pandas DataFrame.

Parameters:
  • study_key (str | None) – Optional study key override.

  • mask_phi (bool) – Whether to mask sensitive PHI fields by default.

  • **filters (Any) – Resource filters passed to list().

Returns:

A pandas DataFrame containing the queried resources.

Raises:

ImportError – If pandas is not installed.

Return type:

DataFrame

class imednet.core.EdcSyncListGetEndpoint[source]

Bases: EdcSyncListEndpoint[T]

Sync EDC list/get endpoint base.

ASYNC_PAGINATOR_CLS

alias of AsyncPaginator

abstract property MODEL: type[T]

The model class associated with this endpoint.

PAGINATOR_CLS

alias of Paginator

abstract property PATH: str

The relative path for the endpoint.

__init__(client)

Initialize the synchronous endpoint.

Parameters:

client (RequesterProtocol) –

Return type:

None

get(study_key, item_id)

Retrieve a single resource by its ID.

Parameters:
  • study_key (str | None) – The study key.

  • item_id (int) – The ID of the resource to retrieve.

Returns:

The requested resource.

Return type:

T

list(study_key=None, **filters)

List resources matching the given filters.

Parameters:
  • study_key (str | None) – Optional study key to override the default.

  • **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) – Resource filters.

Returns:

An iterator over the matching resources.

Return type:

Iterator[T]

requires_study_key: bool = True

Whether this endpoint requires a study key. Defaults to True. Override in subclasses if needed.

to_dataframe(study_key=None, *, mask_phi=True, **filters)

Export queried resources directly to a pandas DataFrame.

Parameters:
  • study_key (str | None) – Optional study key override.

  • mask_phi (bool) – Whether to mask sensitive PHI fields by default.

  • **filters (Any) – Resource filters passed to list().

Returns:

A pandas DataFrame containing the queried resources.

Raises:

ImportError – If pandas is not installed.

Return type:

DataFrame

class imednet.core.HTTPClientBase[source]

Bases: BaseClient, ABC

Shared logic for synchronous and asynchronous HTTP clients.

__init__(api_key=None, security_key=None, base_url=None, timeout=None, tracer=None, retry_config=None, auth=None, transport=None, simulation_mode=None, *, config=None, oidc_token=None, strict_mode=None, credential_source=None)[source]

Initialize the HTTP client and request executor.

Parameters:
  • api_key (str | None) –

  • security_key (str | None) –

  • base_url (str | None) –

  • timeout (float | Timeout | None) –

  • tracer (Any | None) –

  • retry_config (RetryConfig | None) –

  • auth (AuthStrategy | None) –

  • transport (BaseTransport | AsyncBaseTransport | None) –

  • simulation_mode (bool | None) –

  • config (Config | None) –

  • oidc_token (str | None) –

  • strict_mode (bool | None) –

  • credential_source (CredentialSource | None) –

Return type:

None

property retry_policy: RetryPolicy

Return the current retry policy of the executor.

class imednet.core.RetryConfig[source]

Bases: object

Centralized configuration for retry behaviors.

retries: int = 3
backoff_factor: float = 1.0
retry_policy: Any = DefaultRetryPolicy()
max_retry_after: float = 60.0
__init__(retries=3, backoff_factor=1.0, retry_policy=DefaultRetryPolicy(), max_retry_after=60.0)
Parameters:
  • retries (int) –

  • backoff_factor (float) –

  • retry_policy (Any) –

  • max_retry_after (float) –

Return type:

None

create_async_retryer(wait_strategy=None, retry_predicate=None, **kwargs)[source]

Create an asynchronous retryer based on the configuration.

Parameters:
  • wait_strategy (Callable[[Any], float] | None) –

  • retry_predicate (Callable[[Any], bool] | None) –

  • kwargs (Any) –

Return type:

AsyncRetrying

create_retryer(wait_strategy=None, retry_predicate=None, **kwargs)[source]

Create a synchronous retryer based on the configuration.

Parameters:
  • wait_strategy (Callable[[Any], float] | None) –

  • retry_predicate (Callable[[Any], bool] | None) –

  • kwargs (Any) –

Return type:

Retrying

class imednet.core.RetryPolicy[source]

Bases: Protocol

Interface to determine whether a request should be retried.

should_retry(state)[source]

Return True to retry the request for the given state.

Parameters:

state (RetryState) –

Return type:

bool

class imednet.core.RetryState[source]

Bases: object

State information passed to RetryPolicy.

attempt_number: int

Required.

exception: BaseException | None = None
result: Any | None = None
method: str | None = None
__init__(attempt_number, exception=None, result=None, method=None)
Parameters:
  • attempt_number (int) –

  • exception (BaseException | None) –

  • result (Any | None) –

  • method (str | None) –

Return type:

None