Recommended: uv (10× faster installs, lockfile-driven reproducible envs):
git clone https://github.com/getlago/lago-agent-sdk-python
cd lago-agent-sdk-python
uv sync --all-extras # creates .venv, installs from uv.lockPlain pip works too:
python3.11 -m venv venv && source venv/bin/activate
pip install -e '.[dev]'Common workflows are wired through the Makefile:
make sync # install/sync deps from uv.lock
make test # unit tests
make lint # ruff check + ruff format --check + mypy
make format # auto-fix lint and format
make check # lint + test (what CI runs)# Unit tests (fast, no network)
make test
# Unit tests with coverage report
uv run pytest tests/unit --cov=lago_agent_sdk --cov-report=term-missing
# Integration tests (require credentials — see env vars in each test)
AWS_BEARER_TOKEN_BEDROCK="..." \
MISTRAL_API_KEY="..." \
LAGO_API_URL="..." LAGO_API_KEY="..." LAGO_EXTERNAL_SUBSCRIPTION_ID="..." \
uv run pytest tests/integration -qmake lint # all three at once
# or directly:
uv run ruff check src tests
uv run ruff format --check src tests
uv run mypy srcCI gates on all of the above plus an 80% coverage floor. Raising the floor is encouraged as coverage improves.
uv lock --upgrade # refresh the lockfile (commit the diff)
uv lock --upgrade-package X # bump a single packagesrc/lago_agent_sdk/— the SDKsrc/lago_agent_sdk/adapters/— one file per (provider, access path); transforms provider responses intoCanonicalUsagesrc/lago_agent_sdk/wrappers/— one file per (provider SDK, access path); patches client objects in placesrc/lago_agent_sdk/canonical.py— the normalized usage shape sent to Lagosrc/lago_agent_sdk/queue.py— async event queue with backoffsrc/lago_agent_sdk/lago_client.py— thin HTTP client to/events/batchtests/unit/— unit tests, organized to mirrorsrc/tests/unit/adapters/fixtures/— captured real provider responses, used by adapter teststests/integration/— live tests, gated on credential env vars
- Capture real fixtures: write a small script that hits the provider and saves responses to
tests/unit/adapters/fixtures/<provider>/. - Write the adapter at
src/lago_agent_sdk/adapters/<provider>.pythat returnsCanonicalUsage. - Write the wrapper at
src/lago_agent_sdk/wrappers/<provider>.pythat intercepts the customer-facing method. - Update
detector.pyto recognize the client class. - Update
sdk.py::wrap()to dispatch to the new wrapper. - Add unit tests against the captured fixtures.
- Add a live integration test gated on the provider's API key env var.
- Unit tests cover the change
- Existing tests still pass
- Linter clean (
ruff check,mypy src) - CHANGELOG.md updated under
## [Unreleased] - Doc updated if public API changed