Skip to main content

Unofficial Python SDK for the iMednet clinical trials API

Project description

imednet

Unofficial Python SDK for the iMednet clinical trials API.

Full documentation: https://fderuiter.github.io/imednet-python-sdk/

PyPI PyPI - Downloads PyPI - Wheel PyPI - Python Version License CI Coverage

This package simplifies integration with the iMednet REST API for clinical trial management. It provides typed endpoint wrappers, helper workflows and a CLI so researchers and developers can automate data extraction and submission without reimplementing HTTP logic.

Features

  • Simple, consistent interface for API calls
  • Automatic pagination across endpoints
  • Pydantic models for requests and responses
  • Workflow helpers for data extraction and mapping
  • Pandas and CSV utilities
  • Optional in-memory caching of study metadata
  • Structured JSON logging and OpenTelemetry tracing
  • Async client and command line interface
  • Form Designer: Pythonic API for building and validating CRFs

Architecture

The SDK is organized around a core HTTP client layer, endpoint wrappers that model the iMednet API, workflow helpers that combine multiple endpoint calls, and a CLI built on top of those pieces.

graph TD
    CLI[CLI] --> |invokes| Workflows
    Workflows --> |coordinate| Endpoints
    Endpoints --> |use| Client["(HTTP Client)"]
    Client --> |requests| API

Installation

# PyPI release
pip install imednet

Optional Dependencies

To use data export features (SQL, Parquet, Excel) or integrations (Airflow), install the relevant extras:

# Install all export dependencies
pip install "imednet[pandas,sqlalchemy,pyarrow,excel]"

# Or pick specific ones
pip install "imednet[sqlalchemy]"  # For SQL export
pip install "imednet[pyarrow]"     # For Parquet export
pip install "imednet[excel]"       # For Excel export

# For Airflow integration (must be installed manually due to version conflicts)
pip install imednet apache-airflow apache-airflow-providers-amazon

Development Version

pip install git+https://github.com/fderuiter/imednet-python-sdk.git@main

Quick Start

Set your credentials as environment variables before running the examples:

export IMEDNET_API_KEY="your_api_key"
export IMEDNET_SECURITY_KEY="your_security_key"

Synchronous Example

from dotenv import load_dotenv

from imednet import ImednetSDK, load_config
from imednet.utils import configure_json_logging

# Optional: Configure structured JSON logging
configure_json_logging()

# Load credentials from .env file or environment variables
load_dotenv()
cfg = load_config()

with ImednetSDK(
    api_key=cfg.api_key,
    security_key=cfg.security_key,
    base_url=cfg.base_url,
) as sdk:
    # List all studies available to the user
    studies = sdk.studies.list()
    for study in studies:
        print(f"{study.study_name} ({study.study_key})")

Asynchronous Example

import asyncio

from dotenv import load_dotenv

from imednet import AsyncImednetSDK, load_config
from imednet.utils import configure_json_logging

async def main() -> None:
    # Optional: Configure structured JSON logging
    configure_json_logging()

    # Load credentials from .env file or environment variables
    load_dotenv()
    cfg = load_config()

    async with AsyncImednetSDK(
        api_key=cfg.api_key,
        security_key=cfg.security_key,
        base_url=cfg.base_url,
    ) as sdk:
        studies = await sdk.studies.async_list()
        for study in studies:
            print(f"{study.study_name} ({study.study_key})")

asyncio.run(main())

See docs/async_quick_start.rst for more details.


Configuration

The SDK and CLI read credentials from environment variables such as IMEDNET_API_KEY and IMEDNET_SECURITY_KEY. You can set these in your shell or use a .env file. Copy .env.example to .env to get started.

See configuration for the complete list of options. Use imednet.config.load_config() to access these values in your code.


CLI Usage

The package installs an imednet command with subcommands for studies, sites, subjects, records, jobs, queries and more. Use imednet --help to explore all options.

(Note: If you are running the project from source or a local clone, make sure to first install dependencies with poetry install. Then, prefix commands with poetry run, e.g., poetry run imednet --help)

Data Export

Example of exporting a subset of variables:

imednet export sql MY_STUDY table sqlite:///data.db --vars AGE,SEX --forms 10,20

When the connection string uses SQLite, the command splits the output into one table per form to avoid the 2000 column limit (in this case, the table argument is ignored). Pass --single-table to disable this behaviour and use the specified table name. See docs/cli.rst for full examples.


Documentation & Resources


Development & Contributing

Tech Stack

  • Python 3.10–3.12
  • httpx, pydantic, typer, tenacity, python-dotenv

Prerequisites

  • Poetry (for dependency management)
  • Make (optional, for building docs)

Project Structure

.
├── docs/       - Sphinx documentation
├── examples/   - Usage samples
├── imednet/    - SDK package
├── scripts/    - Helper scripts
└── tests/      - Unit and integration tests

Testing & Development

./scripts/setup.sh  # once
poetry run ruff check --fix .
poetry run black --check .
poetry run isort --check --profile black .
poetry run mypy src/imednet
poetry run pytest -q

After running tests, validate documentation builds cleanly (no warnings):

make docs

See AGENTS.md for full documentation guidelines.

Smoke-test workflow

The optional smoke.yml action runs the tests/live suite. It relies on repository secrets APIKEY and SECURITYKEY and sets IMEDNET_RUN_E2E. Use the workflow to confirm real API access on demand or via its nightly schedule. INFO-level log messages stream to the terminal during these runs, making it easier to debug failures.

Building & Publishing

python -m build
python -m twine upload dist/*

Pushing a Git tag like v0.1.4 triggers the GitHub Actions workflow that builds and publishes the package to PyPI.

Versioning & Changelog

This project follows Semantic Versioning. See GitHub Releases for release history.

Contributing

Contributions are welcome! See the contributing guide and CONTRIBUTING.md for full details.


Troubleshooting

Missing or invalid required environment variable(s) If you see an error like Error: IMEDNET_API_KEY and IMEDNET_SECURITY_KEY environment variables must be set. (CLI) or API key and security key are required (SDK), or an "Unauthorized" or "Forbidden" (403) API error, ensure you have set valid keys in your shell or in a .env file in the directory where you run the script (avoid using "dummy" keys). See Configuration.

ModuleNotFoundError when running the CLI locally If you are running the imednet CLI from source (e.g., poetry run imednet) and see a ModuleNotFoundError (such as No module named 'imednet'), ensure you have installed the project dependencies by running poetry install in the project root.


License

This project is licensed under the MIT license. See LICENSE for details.


Acknowledgements

Built with open source libraries including requests, httpx, pydantic and typer.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

imednet-0.5.0.tar.gz (89.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

imednet-0.5.0-py3-none-any.whl (129.0 kB view details)

Uploaded Python 3

File details

Details for the file imednet-0.5.0.tar.gz.

File metadata

  • Download URL: imednet-0.5.0.tar.gz
  • Upload date:
  • Size: 89.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for imednet-0.5.0.tar.gz
Algorithm Hash digest
SHA256 fe92266b5f89aeeee889c1278fe5b273bd217d9870e990221ef8824d42c7b25c
MD5 1618284b6cb7b9a98d45d5d5c15ab592
BLAKE2b-256 3a57eb8ebbef45549ea13b3e0659fa6c1df36e52df9be15c8dc04daba9e73e42

See more details on using hashes here.

Provenance

The following attestation bundles were made for imednet-0.5.0.tar.gz:

Publisher: main.yml on fderuiter/imednet-python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file imednet-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: imednet-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 129.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for imednet-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4f17a12bb7d32559675a77c1fa7511b26faf48ee957b91e7c10e19c94b905f93
MD5 7f5acb39426ec07c8903e6d3d9fc8a78
BLAKE2b-256 0d12a666102cfdc6b9008764be06ed1eca43cf01f75d92a0f424309717177891

See more details on using hashes here.

Provenance

The following attestation bundles were made for imednet-0.5.0-py3-none-any.whl:

Publisher: main.yml on fderuiter/imednet-python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page