Velacent Bridge: beta December 2026, general availability early 2027. E-mail sales to request beta access.

Documentation menu

Python SDK

Last updated . Documentation for the current release. Ask in the product.

velacent is the official client for Python 3.10 or newer (tested on 3.15). It has no runtime dependencies (standard library only), is fully typed and is thread-safe. Read the SDK overview first for what the SDKs do.

Install

Coming: the package will be published on PyPI as velacent (pip install velacent). Until it is, use the Data API over plain HTTP: each example below shows the raw HTTP next to the SDK call. Once published, private-key authentication needs the cryptography package: pip install "velacent[private-key]".

FHIR resources are plain dict objects (FHIR JSON); Bundle and a few other types are small TypedDict models. No FHIR model library is required. If you want full resource models, a permissively licensed library such as fhir.resources can sit on top of the dicts.

Quickstart and raw HTTP, side by side

from velacent import Velacent Bridge

# Reads VELACENT_CLIENT_ID, VELACENT_CLIENT_SECRET and VELACENT_HOST.
# sandbox=True is the one-line switch to the developer sandbox (synthetic data only).
client = Velacent(sandbox=True)
StepRaw HTTPSDK
Get a tokencurl -u "$ID:$SECRET" -d grant_type=client_credentials https://{host}/oauth/tokenautomatic on the first call, cached and refreshed
Send a messagePOST /sandbox/v1/messages with Idempotency-Keyclient.messages.send_fhir(client.sandbox.synthetic_patient())
Read your first patienta _search POST on Patient with an identifier parameter, then GET .../fhir/Patient/{id}client.fhir.find_patient_by_identifier(system, value)
Search, all pagesfollow each Bundle's next linkfor o in client.fhir.search_all("Observation", {"patient": pid, "_count": 50}): ...
Receive a webhookverify X-Velacent-Signature yourselfwsgi_app(secret, on_event) or asgi_app(secret, on_event)
Exportkick off, poll, download NDJSONclient.link(id).fhir.bulk (preview)

Authentication

# Client secret (server side)
Velacent(client_id, client_secret, scopes=["messages:send", "events:read"])

# Private key (SMART Backend Services): the key never leaves your process
from velacent.private_key import private_key_assertion
token_url = "https://{host}/oauth/token"
Velacent(client_id, assertion=private_key_assertion(client_id, token_url, pem_text, key_id="k1"))

# Your own token source
Velacent(token_provider=lambda: fetch_token_from_my_server())

Secrets come from arguments or the environment (VELACENT_CLIENT_ID, VELACENT_CLIENT_SECRET, VELACENT_HOST, VELACENT_ENV, VELACENT_SCOPES). They are never shown in repr, logs or errors. The token is cached for its lifetime and refreshed shortly before it ends; a revoked token is replaced once, automatically.

The Data API

Every operation of the OpenAPI description is a method on client.api (generated, typed). The ergonomic layer covers the common ones:

client.messages.send_fhir(resource)                  # POST /messages, application/fhir+json
client.messages.send_hl7("MSH|^~\\&|...")            # x-application/hl7-v2+er7
client.messages.send_type("my_order", {...})         # POST /messages/{type}

for event in client.events.iterate(): ...            # every event from the start

# Pull mode with a stored cursor (at least once: de-duplicate by event["id"])
client.events.consume(handle, cursor=saved, on_cursor=save, stop=stop_event)

client.webhooks.create("https://your-app.example/velacent", ["message.received"])
for row in client.requests.iterate(status=422): ...  # the request log, newest first

An Idempotency-Key is generated for every POST that accepts one and reused on retries; pass your own with idempotency_key=. Retries follow Retry-After and RateLimit-Reset; tune them with RetryOptions(max_retries=..., base_delay=..., max_server_wait=...). Errors are typed: RateLimitError, PermissionDeniedError, ValidationError, ConflictError, ServerError, OAuthError, ... each with status, code, request_id and retryable.

Partner FHIR access

fhir = client.link("lnk_...").fhir               # a provider's grant to your client
cs = fhir.metadata()                             # what this link can do, nothing more

patient = fhir.find_patient_by_identifier("urn:oid:1.2.3.4", "MRN-001")
# or an exact demographic match: family, given and a FULL birth date; more than one match raises MultiplePatientsError
same = fhir.find_patient_by_demographics("Smith", "Ann", "1980-01-01")

bundle = fhir.search("Observation", {"patient": patient["id"], "category": "laboratory"})
post = fhir.search_post("Observation", {"patient": patient["id"]})   # POST _search: parameters stay out of URLs
for obs in fhir.search_all("Observation", {"patient": patient["id"], "_count": 50}): ...   # all pages

again = fhir.read_if_changed("Observation", "o1", 'W/"3"')          # 304 handled

Paging follows the Bundle's next link, up to the published 50 pages, and refuses a link that leaves the API host. A page holds at most 100 resources (the SDK refuses a larger _count). At most four requests are in flight per link.

Write, and retry a create safely

fhir.create(observation)
fhir.update({**observation, "id": "o1"})

# Idempotency-Key is not supported on FHIR writes (the platform keeps no copy of the provider's answers):
# the SDK raises UnsupportedOptionError and explains. Use conditional create instead:
r = fhir.create_if_none_exist(observation, "https://your-app.example/accession", "A-1001")
# r["created"] is True (201), or False (200): an earlier attempt already went through. 412 raises PreconditionFailedError.

A conditional create is safe to send again after a timeout or a 503; the SDK retries it for you after Retry-After, one request at a time. When metadata() says the conditional create is emulated by Velacent Bridge it is not atomic: do not send two identical creates at the same moment (FhirClient.supports_conditional_create(cs, "Observation") tells you the type supports it).

Bulk export (preview)

The bulk export is written against the standard FHIR Bulk Data flow and marked preview until the Velacent Bridge export is released: it emits a BulkExportPreviewWarning once, it may change, and it is tested only against a local mock.

job = fhir.bulk.start(types=["Patient", "Observation"], since="2026-01-01T00:00:00Z")
manifest = job.wait(on_progress=print)             # honors Retry-After
for resource in fhir.bulk.stream(manifest): ...    # NDJSON, line by line
job.cancel()

Webhooks

from velacent.webhooks import wsgi_app, asgi_app, construct_event

# Flask, Django or any WSGI server: the app reads the raw body itself
app = wsgi_app(secret, on_event)                   # on_event(event: dict) is called once per event id

# FastAPI, Starlette: on_event may be async
hooks = asgi_app(secret, on_event)

# Or by hand, framework-neutral. raw_body must be the exact bytes received.
event = construct_event(raw_body, headers["X-Velacent-Signature"], secret)

The app answers the verification challenge, checks the signature in constant time against every secret you pass (a list during a rotation), refuses a timestamp more than 5 minutes off, ignores a redelivered event id, and answers 500 when your handler raises so Velacent Bridge retries. Event kinds are available as is_message_received, is_test_ping and is_verification; an unknown kind arrives as it is, so ignore it.

Security

  • Keep the client secret and the private key on a server. They are held in an object that cannot be printed or pickled.
  • The SDK never logs secrets, tokens, bodies or query strings, refuses redirects, and sends your token only to the API host.
  • Use search_post when search parameters contain identifiers. The sandbox takes synthetic data only.

Develop

ruff check, mypy --strict, python -m unittest discover -s tests -t . (unit tests against a mock server built from the OpenAPI description, every operation exercised) and node ../scripts/generate.mjs --check (fails when the description changed and the client was not regenerated).


Something unclear or missing? Ask Help in the Velacent Bridge console; answers link to the right screen. How support works.