Skip to content

Generated-model helpers

Version selection + module loading for the codegen-produced modules (dhis2w_client.generated.v{N}).

generated

Version-scoped generated clients. Populated by dhis2 codegen.

Classes

Dhis2

Bases: StrEnum

DHIS2 major version that dhis2w-client has a generated client for.

Members mirror the directory names under dhis2w_client/generated/. Use as a typed hint when you want to pin the client to a specific version instead of letting it auto-detect via /api/system/info:

from dhis2w_client import Dhis2, Dhis2Client
async with Dhis2Client(url, auth=auth, pin_version=Dhis2.V42) as client:
    ...
Source code in packages/dhis2w-client/src/dhis2w_client/generated/__init__.py
class Dhis2(StrEnum):
    """DHIS2 major version that `dhis2w-client` has a generated client for.

    Members mirror the directory names under `dhis2w_client/generated/`. Use as a
    typed hint when you want to pin the client to a specific version instead of
    letting it auto-detect via `/api/system/info`:

        from dhis2w_client import Dhis2, Dhis2Client
        async with Dhis2Client(url, auth=auth, pin_version=Dhis2.V42) as client:
            ...
    """

    V40 = "v40"
    V41 = "v41"
    V42 = "v42"
    V43 = "v43"
    V44 = "v44"

Functions

available_versions()

Return the version keys that have been populated by codegen.

Walks the generated/ folder, imports each v\d+ subpackage, and returns only the ones whose __init__.py set GENERATED = True.

Source code in packages/dhis2w-client/src/dhis2w_client/generated/__init__.py
def available_versions() -> tuple[str, ...]:
    r"""Return the version keys that have been populated by codegen.

    Walks the `generated/` folder, imports each `v\d+` subpackage, and returns
    only the ones whose `__init__.py` set `GENERATED = True`.
    """
    here = Path(__file__).parent
    ready: list[str] = []
    for child in sorted(here.iterdir()):
        if not child.is_dir() or not _VERSION_KEY_RE.match(child.name):
            continue
        try:
            module = importlib.import_module(f"dhis2w_client.generated.{child.name}")
        except ImportError:
            continue
        if getattr(module, "GENERATED", False):
            ready.append(child.name)
    return tuple(ready)

load(version_key)

Import a specific generated version module.

Source code in packages/dhis2w-client/src/dhis2w_client/generated/__init__.py
def load(version_key: str) -> ModuleType:
    """Import a specific generated version module."""
    return importlib.import_module(f"dhis2w_client.generated.{version_key}")