Skip to main content

Context Engine Python Client

Python client for the Clinia Context Engine API. A thin, typed wrapper over httpx with Pydantic v2 models generated from the OpenAPI contract — resource methods, parameters, and response models are fully typed, in both sync and async flavors. Requires Python 3.10+.

Install

pip install clinia-context-engine

Usage

Every Clinia workspace requires authentication. Create OAuth credentials in the Console — scoped to your workspace, with Read & Write if you intend to ingest data or create patients — then point base_url at your workspace:

from clinia_context_engine import ClientCredentials, ContextEngineClient

with ContextEngineClient(
    base_url="https://<workspace-id>.w.clinia.cloud",
    auth=ClientCredentials(client_id="your-client-id", client_secret="your-client-secret"),
) as client:
    patients = client.patients.list_patients()
    report = client.patients.get_resolution("patient-123", page=0, per_page=50)

That is the whole configuration. The client resolves Clinia's authorization server, acquires a bearer token, caches it, refreshes it before expiry, and attaches Authorization: Bearer <token> to every request. Tokens last an hour; you do not manage them.

Methods are grouped by resource (client.patients, client.ingest, client.sessions, client.vfs, client.graph, client.info) and return Pydantic models parsed from the response. Field names are snake_case in Python and mapped to the API's wire names automatically.

Non-2xx responses raise APIStatusError, carrying the parsed error envelope:

from clinia_context_engine import APIStatusError

try:
    client.patients.get_patient("missing")
except APIStatusError as err:
    print(err.status_code, err.error.type if err.error else err.body)

Async

AsyncContextEngineClient is the async twin — same resources, same signatures, awaited:

from clinia_context_engine import AsyncContextEngineClient, ClientCredentials

async with AsyncContextEngineClient(base_url=base_url, auth=credentials) as client:
    patients = await client.patients.list_patients()

Without authentication

Omit auth entirely and the client sends no Authorization header. Useful against a server that does not require one — a stub or recorded fixture in your own tests. An http:// base URL is fine there. Note this is about the client sending no credentials: a Clinia workspace always requires them, so pointing an unauthenticated client at one yields 401s on every request rather than a clear startup failure.

Bring your own token

For a token you obtained elsewhere, a different grant, or a custom refresh strategy, pass auth a callable instead of a config. It is called per request and returns the token to attach:

client = ContextEngineClient(base_url=base_url, auth=lambda: token_store.valid_access_token())

ClientCredentialsTokenProvider (and its async twin) is exactly such a callable, so one cached provider can be shared across several clients.

Bring your own httpx client

Pass http_client an httpx.Client (or httpx.AsyncClient) you configured yourself — proxies, event hooks, a MockTransport in tests. A provided client is not closed by close().

Options

Option Type Description
base_url str Context Engine workspace base URL. Required.
auth ClientCredentials or () -> str callable OAuth2 client-credentials config (common case) or a per-request token callable.
timeout float or httpx.Timeout Request timeout. Defaults to 60 seconds.
http_client httpx.Client / httpx.AsyncClient Preconfigured transport; not closed by the client.

Development

This package is generated from the Context Engine OpenAPI spec on each release — the Pydantic models by datamodel-code-generator, the resource classes from the same spec. Don't edit generated/ or resources/ by hand.

The GitHub repository mirrors each release, so it can't merge pull requests. Report bugs in its issues.

uv sync --group dev
uv run --group dev pytest
uv run --group dev pyright
uv run --group dev ruff check src tests

Changelog

See the Context Engine changelog.

License

Apache-2.0 © Clinia Health Inc.

Metadata

Release files for clinia-context-engine 0.10.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for clinia-context-engine 0.10.1
File Size Uploaded Provenance Actions
clinia_context_engine-0.10.1.tar.gz 40.4 kB Without provenance Details for clinia_context_engine-0.10.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for clinia-context-engine 0.10.1
File Interpreter ABI Platform Actions
clinia_context_engine-0.10.1-py3-none-any.whl Python 3 none any Details for clinia_context_engine-0.10.1-py3-none-any.whl

Total release size: 86.3 kB

Release files / clinia_context_engine-0.10.1.tar.gz

Download URL clinia_context_engine-0.10.1.tar.gz
Size 40.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3a69ccf9be40fab8104c0408899025ad7e1ed8eba663ef5adde2ad9f0daa4f34
BLAKE2b-256 checksum
How to use checksums
376a4036f4316e629fb93c57207d5652ad805cf16504a982c22a64736fc78d35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / clinia_context_engine-0.10.1-py3-none-any.whl

Download URL clinia_context_engine-0.10.1-py3-none-any.whl
Size 45.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4cd959c7e7dcc655489edefd3cdfb9b5b68209e654fda4d344200af1aec4afef
BLAKE2b-256 checksum
How to use checksums
4696889889a07453a93756ed0402536f5dc772ee8b5dbd7813be36e3ccae6f74
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for clinia-context-engine 0.10.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page