imednet.core.endpoint package

Subpackages

Submodules

imednet.core.endpoint.abc module

Abstract base class for all API endpoints.

class imednet.core.endpoint.abc.EndpointABC(*args, **kwargs)[source]

Bases: ABC, ClientProvider, Generic[T]

Abstract base class defining the contract for all API endpoints.

This ensures that all endpoint implementations provide necessary properties like PATH and MODEL, and implement core path building logic.

abstract property MODEL: Type[T]

The model class associated with this endpoint.

abstract property PATH: str

The relative path for the endpoint.

property requires_study_key: bool

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

imednet.core.endpoint.base module

Base endpoint mix-in for all API resource endpoints.

class imednet.core.endpoint.base.GenericEndpoint(client, ctx, async_client=None)[source]

Bases: EndpointABC[T]

Generic base for endpoint wrappers.

Handles context injection and basic path building. Does NOT include EDC-specific logic.

Parameters:
  • client (RequestorProtocol) –

  • ctx (Context) –

  • async_client (Optional[AsyncRequestorProtocol]) –

BASE_PATH = ''
class imednet.core.endpoint.base.GenericListGetEndpoint(client, ctx, async_client=None)[source]

Bases: GenericEndpoint[T], ListEndpointMixin[T], FilterGetEndpointMixin[T]

Generic base for endpoints that provide list and get-by-filter functionality.

Combines GenericEndpoint with ListEndpointMixin and FilterGetEndpointMixin to provide standard CRUD read operations.

Parameters:
  • client (RequestorProtocol) –

  • ctx (Context) –

  • async_client (Optional[AsyncRequestorProtocol]) –

imednet.core.endpoint.edc_mixin module

Mixin for EDC-specific endpoint logic.

class imednet.core.endpoint.edc_mixin.EdcEndpointMixin[source]

Bases: object

Mixin providing EDC-specific logic for endpoints.

This includes the base path for EDC resources and automatic injection of the default study key into filters.

BASE_PATH = '/api/v1/edc/studies'

imednet.core.endpoint.protocols module

class imednet.core.endpoint.protocols.EndpointProtocol(*args, **kwargs)[source]

Bases: Protocol

Protocol defining the interface for endpoint classes.

MODEL: Type[JsonModel]
PAGE_SIZE: int
PATH: str
requires_study_key: bool
class imednet.core.endpoint.protocols.ListEndpointProtocol(*args, **kwargs)[source]

Bases: Protocol[T]

Protocol defining the interface for listing endpoint classes.

imednet.core.endpoint.strategies module

Parameter processing strategies for endpoints.

This module implements the ParamProcessor strategy pattern, allowing endpoints to customize how filters are processed and special parameters are extracted.

class imednet.core.endpoint.strategies.DefaultParamProcessor(*args, **kwargs)[source]

Bases: ParamProcessor

Default parameter processor.

Simply passes filters through without modification.

process_filters(filters)[source]

Return filters as-is and no special parameters.

Parameters:

filters (Dict[str, Any]) – The input filters dictionary.

Return type:

Tuple[Dict[str, Any], Dict[str, Any]]

Returns:

A tuple of (copy of filters, empty dict).

class imednet.core.endpoint.strategies.KeepStudyKeyStrategy(exception_cls=<class 'imednet.errors.client.ClientError'>)[source]

Bases: object

Strategy that requires a study key and keeps it in the filters.

Used when the API expects ‘studyKey’ as a query parameter.

Parameters:

exception_cls (Type[Exception]) –

process(filters)[source]

Extract study key, validate presence, and keep in filters.

Parameters:

filters (Dict[str, Any]) – The filters dictionary.

Return type:

Tuple[Optional[str], Dict[str, Any]]

Returns:

Tuple of (study_key, filters).

Raises:

Exception – If study key is missing (type determined by exception_cls).

class imednet.core.endpoint.strategies.MappingParamProcessor(mapping, defaults=None)[source]

Bases: ParamProcessor

ParamProcessor that maps specific filter keys to API parameters.

Extracts keys defined in the mapping and returns them as special parameters, optionally renaming them according to the mapping values.

Parameters:
  • mapping (Dict[str, str]) –

  • defaults (Dict[str, Any] | None) –

process_filters(filters)[source]

Process filters using the configured mapping.

Parameters:

filters (Dict[str, Any]) – The input filters dictionary.

Return type:

Tuple[Dict[str, Any], Dict[str, Any]]

Returns:

A tuple of (cleaned filters, special parameters).

class imednet.core.endpoint.strategies.OptionalStudyKeyStrategy[source]

Bases: object

Strategy that allows the study key to be optional.

If present, it is kept in the filters.

process(filters)[source]

Extract study key if present.

Parameters:

filters (Dict[str, Any]) – The filters dictionary.

Return type:

Tuple[Optional[str], Dict[str, Any]]

Returns:

Tuple of (study_key_or_none, filters).

class imednet.core.endpoint.strategies.PopStudyKeyStrategy(exception_cls=<class 'imednet.errors.client.ClientError'>)[source]

Bases: object

Strategy that requires a study key but removes it from the filters.

Used when the study key is part of the path or handled separately, not sent as a query parameter.

Parameters:

exception_cls (Type[Exception]) –

process(filters)[source]

Extract study key, validate presence, and remove from filters.

Parameters:

filters (Dict[str, Any]) – The filters dictionary.

Return type:

Tuple[Optional[str], Dict[str, Any]]

Returns:

Tuple of (study_key, modified_filters).

Raises:

Exception – If study key is missing (type determined by exception_cls).

class imednet.core.endpoint.strategies.StudyKeyStrategy(*args, **kwargs)[source]

Bases: Protocol

Protocol for study key handling strategies.

process(filters)[source]

Process the study key from filters.

Parameters:

filters (Dict[str, Any]) – The current filters dictionary.

Return type:

Tuple[Optional[str], Dict[str, Any]]

Returns:

A tuple containing the extracted study key (if any) and the modified filters.

imednet.core.endpoint.structs module

class imednet.core.endpoint.structs.ListRequestState(path, params, study, has_filters, cache, cached_result=None)[source]

Bases: Generic[T]

Encapsulates the state required to execute a list request.

Parameters:
  • path (str) –

  • params (Dict[str, Any]) –

  • study (str | None) –

  • has_filters (bool) –

  • cache (Any) –

  • cached_result (List[T] | None) –

cached_result

The result from cache, if any.

path

The API path for the request.

params

The query parameters.

study

The study key.

has_filters

Whether filters other than study key are present.

cache

The cache object used for this request.

cache: Any
cached_result: Optional[List[TypeVar(T, bound= JsonModel)]] = None
has_filters: bool
params: Dict[str, Any]
path: str
study: Optional[str]
class imednet.core.endpoint.structs.ParamState(study, params, other_filters)[source]

Bases: object

Encapsulates the state of resolved parameters for an endpoint request.

Parameters:
  • study (str | None) –

  • params (Dict[str, Any]) –

  • other_filters (Dict[str, Any]) –

study

The study key, if applicable.

params

The dictionary of query parameters.

other_filters

Remaining filters after study key extraction.

other_filters: Dict[str, Any]
params: Dict[str, Any]
study: Optional[str]

Module contents

Core endpoint abstractions and mixins.

class imednet.core.endpoint.FilterGetEndpointMixin(*args, **kwargs)[source]

Bases: EndpointABC[T]

Mixin implementing get via filtering.

ASYNC_PAGINATOR_CLS

alias of AsyncPaginator

PAGINATOR_CLS

alias of Paginator

async async_get(study_key, item_id)[source]

Asynchronously get an item by ID using filtering.

Return type:

TypeVar(T, bound= JsonModel)

Parameters:
  • study_key (str | None) –

  • item_id (Any) –

get(study_key, item_id)[source]

Get an item by ID using filtering.

Return type:

TypeVar(T, bound= JsonModel)

Parameters:
  • study_key (str | None) –

  • item_id (Any) –

class imednet.core.endpoint.ListEndpointMixin(*args, **kwargs)[source]

Bases: ParamMixin, CacheMixin, ParsingMixin[T], EndpointABC[T]

Mixin implementing list helpers.

ASYNC_PAGINATOR_CLS

alias of AsyncPaginator

PAGE_SIZE: int = 100
PAGINATOR_CLS

alias of Paginator

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

List items asynchronously.

Return type:

List[TypeVar(T, bound= JsonModel)]

Parameters:
  • study_key (str | None) –

  • filters (Any) –

async async_list_by_attribute(attr_name, target_value, study_key=None, **filters)[source]

Asynchronously list items filtered by a specific attribute.

Return type:

List[TypeVar(T, bound= JsonModel)]

Parameters:
  • attr_name (str) –

  • target_value (Any) –

  • study_key (str | None) –

  • filters (Any) –

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

List items.

Return type:

List[TypeVar(T, bound= JsonModel)]

Parameters:
  • study_key (str | None) –

  • filters (Any) –

list_by_attribute(attr_name, target_value, study_key=None, **filters)[source]

List items filtered by a specific attribute.

Return type:

List[TypeVar(T, bound= JsonModel)]

Parameters:
  • attr_name (str) –

  • target_value (Any) –

  • study_key (str | None) –

  • filters (Any) –

class imednet.core.endpoint.ParsingMixin[source]

Bases: Generic[T]

Mixin implementing model parsing helpers.

MODEL: Type[TypeVar(T, bound= JsonModel)]
class imednet.core.endpoint.PathGetEndpointMixin(*args, **kwargs)[source]

Bases: ParsingMixin[T], EndpointABC[T]

Mixin implementing get via direct path.

async async_get(study_key, item_id)[source]

Asynchronously get an item by ID using direct path.

Return type:

TypeVar(T, bound= JsonModel)

Parameters:
  • study_key (str | None) –

  • item_id (Any) –

get(study_key, item_id)[source]

Get an item by ID using direct path.

Return type:

TypeVar(T, bound= JsonModel)

Parameters:
  • study_key (str | None) –

  • item_id (Any) –