Skip to main content

PyDOGE API is an advanced, Python wrapper for interacting with the public-facing API of the Department of Government Efficiency (DOGE)

Project description

PyDOGE Logo

PyDOGE API

A modern, fully-typed Python SDK for the U.S. Department of Government Efficiency (DOGE) API — pull cancelled grants, contracts, leases, and payments, then analyze, export, and visualize them in a few lines.

PyPI version Python versions Downloads CI Docs License: MIT

📃 Documentation  ·  📦 PyPI  ·  🐛 Report a bug


PyDOGE API wraps the public DOGE API — a federal transparency initiative publishing detailed data on 💸 cancelled grants, 📑 contract terminations, 🏢 lease reductions, and 🧾 payment transactions — and turns it into a smooth workflow for data scientists, analysts, and journalists.

✨ Highlights

Feature What you get
🔄 Auto-pagination Fetch one page or every page (fetch_all=True), sync or async
🧱 Typed responses Pydantic v2 models — or plain dicts when you prefer
🐼 DataFrames .to_dataframe() with automatic date parsing
💾 One-line export CSV / Excel / JSON, timestamped
📊 Instant summary rows, nulls, dtypes, and stats via .summary()
🧮 Combined dataset savings.all() — grants + contracts + leases in one tidy frame
📈 Built-in charts bar, time-series, distribution, US-state choropleth ([viz] extra)
🖥️ Modern CLI pydoge — Typer + Rich, fetch/export/summarize from the terminal
🔁 Retry-safe client exponential backoff on 429/5xx, with a cap
🔒 Secure logging credential scrubbing + on-demand masking via PyLogShield

📦 Installation

pip install pydoge-api              # core
pip install "pydoge-api[viz]"      # + charts (matplotlib, plotly)

Requires Python 3.9+.

⚡ Quickstart

from pydoge_api import DogeAPI

with DogeAPI(fetch_all=True) as api:
    grants = api.savings.get_grants(sort_by="savings")

    print(grants.meta.total_results)        # e.g. 15887
    df = grants.to_dataframe()              # pandas DataFrame, dates parsed
    grants.summary()                        # rows / nulls / dtypes / stats
    grants.export("grants", format="csv")  # -> grants_YYYYMMDD_HHMMSS.csv

Prefer the combined savings dataset?

with DogeAPI(fetch_all=True) as api:
    df = api.savings.all()                  # grants + contracts + leases, with a `kind` column

print(df.groupby("kind")["savings"].sum())

🖥️ Command line

No Python required — the pydoge CLI ships with the package:

pydoge grants --sort-by savings --limit 10                       # Rich preview table
pydoge payments --filter agency_name --filter-value NASA --summary
pydoge contracts --fetch-all --export csv --out contracts        # timestamped CSV
pydoge all --export json                                          # combined dataset

📈 Visualize in one line

from pydoge_api import DogeAPI, viz        # pip install "pydoge-api[viz]"

with DogeAPI(fetch_all=True) as api:
    df = api.savings.get_grants(sort_by="savings").to_dataframe()

viz.plot_top_agencies(df, metric="savings", top_n=10)
Top 10 agencies by grant savings

Also available: plot_over_time, plot_distribution, plot_cumulative, and an interactive US-state plot_state_choropleth for leases.

📚 More examples

Contracts, leases & payments
from pydoge_api import DogeAPI

with DogeAPI(fetch_all=True) as api:
    contracts = api.savings.get_contracts(sort_by="value")
    leases    = api.savings.get_leases(sort_by="savings")
    payments  = api.payments.get_payments(filter="agency_name", filter_value="NASA")

    for resp, name in [(contracts, "contracts"), (leases, "leases"), (payments, "payments")]:
        resp.summary()
        resp.export(name, format="xlsx")

Sort fields: savings endpoints accept savings | value | date; payments accept amount | date. Payment filters: agency_name | date | org_name.

Output modes & async
# Plain dicts instead of Pydantic models (still export-capable)
with DogeAPI(output_pydantic=False) as api:
    grants = api.savings.get_grants()
    grants.export("grants", format="json")

# Raw httpx.Response (no parsing)
with DogeAPI(handle_response=False) as api:
    resp = api.savings.get_grants()
    print(resp.status_code, resp.json()["meta"])

# Concurrent pagination for large pulls
with DogeAPI(fetch_all=True, run_async=True) as api:
    payments = api.payments.get_payments()
Without a context manager
api = DogeAPI(fetch_all=True)
try:
    grants = api.savings.get_grants(sort_by="savings")
    grants.export("grants", format="csv")
finally:
    api.close()
Error handling
from pydoge_api import DogeAPI, DogeAPIRequestError

with DogeAPI() as api:
    try:
        grants = api.savings.get_grants()
    except DogeAPIRequestError as err:
        print(err.status_code, err.url)   # raised after retries / on non-retriable errors

🔒 Secure logging

PyDOGE logs through PyLogShield — cloud-credential prefixes (AWS_, AZURE_, GCP_, TOKEN, …) are scrubbed automatically, and you can mask secrets per call. The logger is created lazily, so import pydoge_api has no side effects.

from pydoge_api._logging import get_logger

log = get_logger("pydoge_api", enable_json=True)
log.warning("api_key=SECRET123", mask=True)   # -> api_key=***

📖 Documentation

🤝 Contributing

Contributions are welcome! Open an issue with the enhancement label, or fork the repo and send a pull request. If PyDOGE API is useful to you, please ⭐ the project — it helps.

📝 License

Released under the MIT License.

(back to top)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydoge_api-0.3.2.tar.gz (584.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydoge_api-0.3.2-py3-none-any.whl (30.9 kB view details)

Uploaded Python 3

File details

Details for the file pydoge_api-0.3.2.tar.gz.

File metadata

  • Download URL: pydoge_api-0.3.2.tar.gz
  • Upload date:
  • Size: 584.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for pydoge_api-0.3.2.tar.gz
Algorithm Hash digest
SHA256 3e626226fc7e42d83a627c7ebdb1bf38e32300c2b348be36566738db4041b025
MD5 7dbcb24e0ad291dc448dc2f3eb760529
BLAKE2b-256 d40e66972ad2b9fc31987b0dba25f422bd591f21d7840eaafc37072bcb7a4c31

See more details on using hashes here.

File details

Details for the file pydoge_api-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: pydoge_api-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 30.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for pydoge_api-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b38de86f70afe37f9606149f6ed269b3ffcbb3d50d852c50dfa7b5b61a286e7a
MD5 0a0cbe67f61b749c2c6dcfd1bbd67ec6
BLAKE2b-256 7bdff01b735750c4ae5a7857393436a5f2e4958d11aa38a29e0123840e6a4bb3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page