Skip to main content

iaso-client

iaso-client is a Python client library for interacting with IASO APIs.

Installation

From the project root:

uv sync

Configuration

  1. Copy .env.sample to .env at the project root, then fill in your credentials:

The IASO_BASE_URL can't be provided with a trailing slash at the end.

IASO_BASE_URL=https://your.iaso-server.com

IASO_LOGIN=your_login
IASO_PASSWORD=your_password
or
IASO_API_TOKEN=your_api_token
  1. Create a symlink so Bruno can read the root .env file:
    • Windows (Run Command Prompt as Administrator):
      cd bruno
      mklink .env ..\.env
      
    • Mac / Linux:
      cd bruno
      ln -s ../.env .env
      

Quickstart

import os

from iaso_client import IasoClient

IASO_BASE_URL = os.getenv("IASO_BASE_URL")
IASO_LOGIN = os.getenv("IASO_LOGIN")
IASO_PASSWORD = os.getenv("IASO_PASSWORD")

client = IasoClient(base_url=IASO_BASE_URL)
client.login(username=IASO_LOGIN, password=IASO_PASSWORD)
page = client.org_unit_types_list(page=1, max_page_size=50, project=975)
items = client.org_unit_types_list(search="District/Zone de sante - DIST")

print(page)
print(items)

Authentication

Use login() with either a username and password, or an existing API token. Arguments must be passed by name.

client.login(username="your_login", password="your_password")
# or
client.login(api_token="your_api_token")

The API token is the same JWT IASO returns from POST /api/token/ (access) or GET /api/apitoken/, so OpenHEXA pipelines and the IASO MCP can pass it as a secret (IASO_API_TOKEN / iaso_token) without a password. A token that already includes the Bearer prefix is accepted.

Passing the username and password positionally (client.login(user, password)) still works but is deprecated.

Raw API calls

Use raw() to call IASO GET endpoints that do not have a typed SDK method yet. The path is relative to /api/. Raw JSON calls are paginated by default with page=1 and max_page_size=50.

entities = client.raw("entities/")
print(entities)

Query parameters can be passed with params:

entities = client.raw(
    "entities/",
    params={"entity_type_ids": 12},
    page=2,
    max_page_size=100,
)

Current typed resources

The current typed client API supports:

Resource Endpoint
Org units /api/orgunits/
Org unit types /api/v2/orgunittypes/
Forms /api/forms/
Form versions /api/formversions/
Instances /api/instances/
Instance files /api/instances/attachments/, /api/instances/attachments_count/

Org units:

client.org_units_list(...)
client.org_units_list(page=...)
client.org_units_list(format="dataframe")
client.org_units_list(format="csv", output_path=...)
client.org_units_list(format="xlsx", output_path=...)
client.org_units_retrieve(...)

Exporting org units to files

Use org_units_list() with format="csv" or format="xlsx" to download the IASO org units export:

client.org_units_list(format="xlsx", output_path="exports/org_units")
client.org_units_list(format="csv", output_path="/tmp/org_units.csv")
client.org_units_list(format="xlsx", output_path="~/exports/org_units")

Org unit list filters such as search, org_unit_type_id, source_id, project, group, version, with_shape, with_location, parent_id, and org_unit_parent_ids can also be used for CSV and XLSX exports.

See Export output paths for file path behavior.

Org unit types:

client.org_unit_types_list(...)
client.org_unit_types_list(page=...)
client.org_unit_types_list(format="dataframe")
client.org_unit_types_retrieve(...)
client.org_unit_types_hierarchy(...)

Forms:

client.forms_list(...)
client.forms_list(page=...)
client.forms_list(format="dataframe")
client.forms_list(format="csv", output_path=...)
client.forms_list(format="xlsx", output_path=...)
client.forms_retrieve(...)

Exporting forms to files

Use forms_list() with format="csv" or format="xlsx" to download the IASO forms export:

client.forms_list(format="xlsx", output_path="exports/forms")
client.forms_list(format="csv", output_path="/tmp/forms.csv")
client.forms_list(format="xlsx", output_path="~/exports/forms")

See Export output paths for file path behavior.

Form versions:

client.form_versions_list(...)
client.form_versions_list(page=...)
client.form_versions_list(format="dataframe")
client.form_versions_retrieve(...)

Instances:

client.instances_list(...)
client.instances_list(page=...)
client.instances_list(format="dataframe")
client.instances_list(format="csv", form_id=..., output_path=...)
client.instances_list(format="xlsx", form_id=..., output_path=...)
client.instances_retrieve(...)

Exporting instances to files

Use instances_list() with format="csv" or format="xlsx" to download the IASO instances export:

client.instances_list(format="xlsx", form_id=123, output_path="exports/instances")
client.instances_list(format="csv", form_id=123, output_path="/tmp/instances.csv")

See Export output paths for file path behavior.

Export output paths

output_path must be a file path, not only a directory. It can be absolute, relative, or start with ~. Relative paths are resolved from the current working directory of the Python process, meaning the directory where the command is run, not where iaso-client is installed.

The parent directory must already exist and the target file must not already exist. You can omit the extension: the client automatically adds .csv or .xlsx based on the requested format.

Instance files:

client.instance_files_list(...)
client.instance_files_list(page=...)
client.instance_files_list(format="dataframe")
client.instance_files_count(...)

Instances:

client.instances_list(...)
client.instances_list(page=...)
client.instances_retrieve(...)

Pagination behavior

*_list() fetches and aggregates results across all pages.
*_list(page=...) returns a single paginated response.
*_list(format="dataframe") returns all matching results as a pandas DataFrame.
The `max_page_size` parameter controls max page size and must be between `50` and `2000`.
Paginated calls are JSON-only: `page=...` cannot be combined with `format="dataframe"`, `format="csv"`, or `format="xlsx"`.

HTTP request logging

You can enable request logging when creating the client:

import logging
from iaso_client import IasoClient

logging.basicConfig(level=logging.INFO)

client = IasoClient(
    base_url="https://your.iaso-server.com",
    enable_logging=True,
)

Example log output:

GET https://iaso-staging.bluesquare.org/api/v2/orgunittypes/ -> 200 [143.21 ms]

Development

Run tests

uv run pytest

Run the main script

uv run .\examples\main.py

Setup Pre-commit hooks

  1. To ensure your code is properly formatted and linted before every commit, install the pre-commit hook:
uv run pre-commit install
  1. Linting & Formatting (Ruff) Format the code (auto-fix styling issues):
uv run ruff format .
  1. Check for logic errors and bad practices:
uv run ruff check .

Bruno

This repository also contains a Bruno collection for manually testing IASO API requests.

Configure the environment

Copy .env.sample to .env in the bruno folder, then fill in your credentials:

IASO_BASE_URL=https://your.iaso-server.com
IASO_LOGIN=your_login
IASO_PASSWORD=your_password
IASO_API_TOKEN=your_api_token

Run Bruno requests

  1. Open Bruno.
  2. In the top-left corner, open the collection and select the bruno directory from this repository.
  3. In the top-right corner, select the iaso_client environment for the current collection.
  4. Before running any protected request, run the login request first to authenticate.
  5. Then select the request you want to run and click -> to execute it.

Metadata

Release files for iaso-client 1.3.0

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

Source distribution (sdist)

Source distribution for iaso-client 1.3.0
File Size Uploaded Provenance Actions
iaso_client-1.3.0.tar.gz 19.8 kB Without provenance Details for iaso_client-1.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for iaso-client 1.3.0
File Interpreter ABI Platform Actions
iaso_client-1.3.0-py3-none-any.whl Python 3 none any Details for iaso_client-1.3.0-py3-none-any.whl

Total release size: 49.1 kB

Release files / iaso_client-1.3.0.tar.gz

Download URL iaso_client-1.3.0.tar.gz
Size 19.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c542e5fd75513b66491f6e54c13e1996909b8240fc6fac734ed2b79dc04c4509
BLAKE2b-256 checksum
How to use checksums
e056d32334ad5feab047272ccb4152f0d8f164a899a934a32331a9188c81428e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / iaso_client-1.3.0-py3-none-any.whl

Download URL iaso_client-1.3.0-py3-none-any.whl
Size 29.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2661a56640d666486d2a445424876b65c342188b11cb99afe1164780e5b45262
BLAKE2b-256 checksum
How to use checksums
02831b4c768d2dc25ce3e2ec301f73acb4209c1137bcc5166c9d0cf5f2e8d272
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for iaso-client 1.3.0

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