Async DHIS2 API client with pluggable auth (Basic, PAT, OAuth2/OIDC) and pydantic models.
Project description
dhis2w-client
Pure async DHIS2 API client for Python. Pluggable auth (Basic / PAT / OAuth2-OIDC PKCE), pydantic-typed models from both /api/schemas and /api/openapi.json codegen, retry policy, period math, analytics helper. DHIS2 v41, v42, and v43.
Standalone — no profile system, no plugin runtime. Drop it in any async Python project that needs to talk to a DHIS2 instance.
Install
# Inside a uv-managed project
uv add dhis2w-client
Quickstart
from dhis2w_client import BasicAuth, Dhis2Client
async with Dhis2Client(
base_url="https://play.im.dhis2.org/dev-2-43",
auth=BasicAuth(username="admin", password="district"),
) as client:
me = await client.system.me()
print(me.username)
elements = await client.resources.data_elements.list(fields="id,name", page_size=10)
for de in elements:
print(de.id, de.name)
PAT and OAuth2 (with token caching + refresh) work the same way:
from dhis2w_client import Dhis2Client, OAuth2Auth
auth = OAuth2Auth(
base_url="https://dhis2.example.org",
client_id="my-app",
client_secret="...",
scope="ALL",
redirect_uri="http://localhost:8765",
token_store=my_token_store,
store_key="profile:prod",
)
async with Dhis2Client("https://dhis2.example.org", auth=auth) as client:
...
What's in the box
- Async HTTP via httpx with a pluggable retry transport (429 / 502 / 503 / 504 with
Retry-Afterhonoring). - Typed metadata accessors for every resource DHIS2 exposes via
/api/schemas— generated per DHIS2 version underdhis2w_client.generated.v{41,42,43}. - Tracker read + write helpers (
client.tracker.register / enroll / event_create / outstanding). - Analytics —
client.analytics.aggregate(dx=..., pe=..., ou=...) -> Gridfor parsed responses,stream_to(...)for very large pivots. - Period math —
parse_period,next_period_id,previous_period_id,period_start_endacross all six absolute period shapes. - Pluggable auth —
BasicAuth,PatAuth,OAuth2Auth. Add your own by implementing theAuthProviderProtocol. - Bulk operations —
patch_bulk,apply_sharing_bulk, with explicitconcurrencycap (asyncio.Semaphore).
Documentation
Full docs at https://winterop-com.github.io/dhis2w-utils/.
The dhis2w-client package is one member of the dhis2w-utils workspace. The CLI (dhis2w-cli), MCP server (dhis2w-mcp), and Playwright helpers (dhis2w-browser) all build on this client.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dhis2w_client-0.19.0.tar.gz.
File metadata
- Download URL: dhis2w_client-0.19.0.tar.gz
- Upload date:
- Size: 2.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0966af534358a8dbd503d2caec19e26a7b0f9f5ff990c2d5e43e7272ba2c3f9
|
|
| MD5 |
474eae2bc77caad34d79f3d4365ed4ec
|
|
| BLAKE2b-256 |
31d6264c2192ee11b40fba6035fe7119341226f598448c2bda7d7e6430def722
|
Provenance
The following attestation bundles were made for dhis2w_client-0.19.0.tar.gz:
Publisher:
pypi-publish.yml on winterop-com/dhis2w-utils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dhis2w_client-0.19.0.tar.gz -
Subject digest:
a0966af534358a8dbd503d2caec19e26a7b0f9f5ff990c2d5e43e7272ba2c3f9 - Sigstore transparency entry: 1748965340
- Sigstore integration time:
-
Permalink:
winterop-com/dhis2w-utils@a4a230259ee1ab5deae600fd8ae455c8ff713113 -
Branch / Tag:
refs/tags/v0.19.0 - Owner: https://github.com/winterop-com
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@a4a230259ee1ab5deae600fd8ae455c8ff713113 -
Trigger Event:
push
-
Statement type:
File details
Details for the file dhis2w_client-0.19.0-py3-none-any.whl.
File metadata
- Download URL: dhis2w_client-0.19.0-py3-none-any.whl
- Upload date:
- Size: 3.4 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
905a9836eb59b1b5b2d3507b5cf83d2a359eabddb4397bd1a0f65b8dfe33afec
|
|
| MD5 |
ac2b4003c2b4c16abb5e2c0b96e317ef
|
|
| BLAKE2b-256 |
403ccb333d2fc3fcfe10796b02adced7a6e163cd65860636d417852f4cd335c1
|
Provenance
The following attestation bundles were made for dhis2w_client-0.19.0-py3-none-any.whl:
Publisher:
pypi-publish.yml on winterop-com/dhis2w-utils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dhis2w_client-0.19.0-py3-none-any.whl -
Subject digest:
905a9836eb59b1b5b2d3507b5cf83d2a359eabddb4397bd1a0f65b8dfe33afec - Sigstore transparency entry: 1748966158
- Sigstore integration time:
-
Permalink:
winterop-com/dhis2w-utils@a4a230259ee1ab5deae600fd8ae455c8ff713113 -
Branch / Tag:
refs/tags/v0.19.0 - Owner: https://github.com/winterop-com
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@a4a230259ee1ab5deae600fd8ae455c8ff713113 -
Trigger Event:
push
-
Statement type: