Skip to main content

USASpending ORM

Tests PyPI Python

USASpending ORM is a typed, ORM-style Python interface to the USAspending.gov API. It provides fluent query builders and navigable models for federal awards, transactions, recipients, agencies, spending summaries, Treasury Account Symbols, and bulk downloads.

The library is maintained by The Planetary Society.

Why use it?

  • Express complex USAspending searches through chainable Python methods.
  • Work with normalized models, date values, and exact Decimal amounts.
  • Navigate from awards to recipients, agencies, transactions, funding, accounts, and subawards.
  • Retain the original API response through each model's .raw property.
  • Use built-in pagination, retries, rate limiting, optional caching, and result safeguards.

No API key is required.

Installation

uv add usaspending-orm

Or with pip: python -m pip install usaspending-orm. Requires Python 3.9 or newer.

Quickstart

from usaspending import USASpendingClient

with USASpendingClient() as client:
    awards = (
        client.awards.search()
        .contracts()
        .agency("National Aeronautics and Space Administration")
        .recipient_search_text("Space Exploration Technologies")
        .fiscal_year(2024)
        .order_by("Award Amount", "desc")
        .limit(5)
    )

    for award in awards:
        amount = award.total_obligation or 0
        print(f"{award.award_identifier}: {award.recipient.name} - ${amount:,.2f}")

Queries are lazy. Building the chain makes no request; iteration, .first(), .all(), .count(), len(query), indexing, and truth-value testing execute the appropriate USAspending operation.

Documentation

The full documentation covers:

The repository includes Read the Docs configuration for the published site.

Development

git clone https://github.com/planetary-society/usaspending-orm.git
cd usaspending-orm
uv sync --locked --group docs

uv run pytest -q
uv run ruff check src/ tests/
uv run ruff format --check src/ tests/
uv run --group docs mkdocs build --strict

Integration tests make live USAspending requests and run separately:

uv run pytest -m integration -q

Preview the documentation site locally with uv run --group docs mkdocs serve.

Note for contributors

Documentation examples are enforced, not just reviewed. tests/test_documentation.py compiles every fenced python block under docs/, checks that method names cited in prose exist on the public API, and executes most blocks against the live API under the integration marker. Adding or removing an example changes the runnable count, so update _EXPECTED_RUNNABLE_BLOCKS in the same change.

The public API surface is snapshot-tested. When a deliberate change adds, removes, or alters a public callable, regenerate the fixture and review the diff:

USASPENDING_REGEN_API_SURFACE=1 uv run pytest tests/test_public_api_surface.py

The published site builds from .readthedocs.yaml. To activate hosting: import planetary-society/usaspending-orm in Read the Docs, use usaspending-orm as the project slug, and enable pull-request builds. Keep latest as the default until a release tag contains the docs configuration, then make stable the default user-facing version while retaining latest for main.

Project status

The project is in beta. USAspending itself changes over time, and live federal data is revised as agencies submit corrections. Counts and values shown in examples should not be treated as permanent fixtures.

See CHANGELOG.md for release history and compatibility notes.

License

USASpending ORM is released under the MIT License.

Metadata

Release files for usaspending-orm 0.10.1

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

Source distribution (sdist)

Source distribution for usaspending-orm 0.10.1
File Size Uploaded Provenance Actions
usaspending_orm-0.10.1.tar.gz 544.9 kB Without provenance Details for usaspending_orm-0.10.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for usaspending-orm 0.10.1
File Interpreter ABI Platform Actions
usaspending_orm-0.10.1-py3-none-any.whl Python 3 none any Details for usaspending_orm-0.10.1-py3-none-any.whl

Total release size: 771.4 kB

Release files / usaspending_orm-0.10.1.tar.gz

Download URL usaspending_orm-0.10.1.tar.gz
Size 544.9 kB
Tags Source
SHA-256 checksum
How to use checksums
dde2ab49e93e39101049de63587f7d6ecf01eee8c4c355fc83935116054e7783
BLAKE2b-256 checksum
How to use checksums
6339a9ad573f6cd91c2b3e2773f5a9f2675ab0603e809b5eaaf5a849f3391550
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / usaspending_orm-0.10.1-py3-none-any.whl

Download URL usaspending_orm-0.10.1-py3-none-any.whl
Size 226.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bd39ff5022a3c7cedc6b091273a694d4eec737b23b41de14869129fe8b09e725
BLAKE2b-256 checksum
How to use checksums
69074d9353b2fdce7ab5432627a10cd69b364f3a9df7a0e9e99e1650a2bc9937
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for usaspending-orm 0.10.1

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