Async Quick Start
This page shows a minimal asynchronous example using AsyncImednetSDK.
Important
AsyncImednetSDK and ImednetSDK have strictly separate lifecycles.
Bridging synchronous code with async teardowns is not supported.
Always manage
AsyncImednetSDKwithasync withor by explicitly callingawait sdk.aclose()within an active event loop.Calling the synchronous
close()method onAsyncImednetSDKraises aTypeError.Using
with AsyncImednetSDK(...)(the synchronous context manager) raises aTypeError.
Install the package from PyPI:
pip install imednet
Set your credentials by copying the environment template or exporting them directly:
# Option 1: Use a .env file (recommended)
cp .env.example .env
# Option 2: Export directly to your shell
export IMEDNET_API_KEY="your_api_key"
export IMEDNET_SECURITY_KEY="your_security_key"
# Optional: Custom base URL for the API endpoint
# export IMEDNET_BASE_URL="https://edc.prod.imednetapi.com"
List studies asynchronously and poll a job:
import asyncio
from dotenv import load_dotenv
from imednet import AsyncImednetSDK, load_config
from imednet.utils import configure_json_logging
async def main() -> None:
configure_json_logging()
# Note: Ensure you've run `cp .env.example .env` or exported keys to your shell.
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})")
status = await sdk.async_poll_job("STUDY", "BATCH", interval=2, timeout=60)
print(status)
asyncio.run(main())
For synchronous usage, see Quick Start.
The example script Async Quick Start Script provides a runnable version that
validates required environment variables and optionally polls a job when
IMEDNET_JOB_STUDY_KEY and IMEDNET_BATCH_ID are set.