PyDOGE API is an advanced, Python wrapper for interacting with the public-facing API of the Department of Government Efficiency (DOGE)
Project description
A Python library to interact with the Department of Government Efficiency (DOGE) API.
🧾 Table of Contents
🐍 About The Project
PyDOGE API is an advanced, Python wrapper for interacting with the public-facing API of the Department of Government Efficiency (DOGE) — a federal initiative aimed at increasing transparency and fiscal accountability by sharing detailed datasets on:
- 💸 Cancelled grants
- 📑 Contract terminations
- 🏢 Lease reductions
- 🧾 Payment transactions
🚀 Features
- Auto-pagination (sync or async, fetch all pages if needed)
.export()to CSV, Excel, or JSON with timestamped filenames.to_dataframe()for Pandas users.summary()with analytics (rows, nulls, dtypes, stats)summary(save_as="...")for file logging- Returns Pydantic models & dict output
- Retry-safe client with 429 handling
savings.all()— one tidy DataFrame across grants, contracts & leases- 🖥️ Modern
pydogeCLI (Typer + Rich) for fetch / export / summary - 📈 Built-in charts (bar, time-series, distribution, US-state choropleth) via the
[viz]extra - 🔒 Secure logging powered by PyLogShield
This package enables data scientists and analysts to programmatically access and analyze the data with ease.
📌 Getting Started
Installation
Install:
pip install pydoge-api
Upgrade:
pip install --upgrade pydoge-api
Documentation
Full developer docs with API reference, usage, and model schema:
📚 Usage
Get Grants and sorted by savings
from pydoge_api import DogeAPI
with DogeAPI(fetch_all=True, run_async=False) as api:
grants = api.savings.get_grants(sort_by="savings")
df = grants.to_dataframe()
print(df.head())
# Export to CSV
grants.export("grants_q1", format="csv")
# Show summary in terminal
grants.summary(verbose=True)
# Save the summary as markdown
grants.summary(save_as="logs/grants_summary.md")
Get Contracts and sorted by savings
with DogeAPI(fetch_all=True, run_async=False) as api:
contracts = api.savings.get_contracts(sort_by="savings")
df = contracts.to_dataframe()
print(df.head())
# Export to CSV
contracts.export("contracts_q1", format="csv")
# Show summary in terminal
contracts.summary(verbose=True)
# Save the summary as markdown
contracts.summary(save_as="logs/contracts_summary.md")
Get Leases
with DogeAPI(fetch_all=True, run_async=False) as api:
leases = api.savings.get_leases()
df = leases.to_dataframe()
print(df.head())
# Export to CSV
leases.export("leases_q1", format="csv")
# Show summary in terminal
leases.summary(verbose=True)
# Save the summary as markdown
leases.summary(save_as="logs/leases_summary.md")
Get Payments and filter payments by agency
with DogeAPI(fetch_all=True, run_async=False) as api:
payments = api.payments.get_payments(filter="agency_name", filter_value="NASA")
df =payments.to_dataframe()
print(df.head())
# Export to CSV
payments.export("payments_q1", format="csv")
# Show summary in terminal
payments.summary(verbose=True)
# Save the summary as markdown
payments.summary(save_as="logs/payments_summary.md")
Without using Context Manager
api = DogeAPI(
fetch_all=True, # Get all records if True. Default False
run_async=False # For Async set this to True
)
try:
# Get Grants and sorted by savings
grants = api.savings.get_grants(sort_by="savings")
# Get Contracts and sorted by savings
contracts = api.savings.get_contracts(sort_by="savings")
# Get Leases
leases = api.savings.get_leases()
# Get Payments and filter payments by agency
payments = api.payments.get_payments(filter="agency_name", filter_value="NASA")
# Export to CSV
grants.export("grants_q1", format="csv")
# Show summary in terminal
grants.summary(verbose=True)
# Save the summary as markdown
grants.summary(save_as="logs/grants_summary.md")
finally:
api.close()
🔒 Secure Logging
PyDOGE API logs through PyLogShield instead of
the bare standard library. Out of the box this scrubs cloud-credential prefixes
(AWS_, AZURE_, GCP_, GOOGLE_, TOKEN) from every record, and you can opt into
sensitive-value masking per call:
from pydoge_api._logging import get_logger
# Customize the SDK logger (e.g. JSON output, a custom log directory)
log = get_logger("pydoge_api", enable_json=True)
log.warning("token=abc123 leaked into a message", mask=True) # -> token=***
The logger is created lazily on the first log call (so
import pydoge_apihas no side effects). On first use PyLogShield writes to~/.logs/pydoge_api.log; passadd_console=Falseor a customlog_directorytoget_logger(...)to change this.
👪 Contributors
All contributions are welcome. If you have a suggestion that would make this better, please fork the repo and create a merge request. You can also simply open an issue with the label 'enhancement'.
Don't forget to give the project a star! Thanks again!
👏 Acknowledgments
Inspiration, code snippets, etc.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydoge_api-0.3.0.tar.gz.
File metadata
- Download URL: pydoge_api-0.3.0.tar.gz
- Upload date:
- Size: 540.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de48dab911a7a34264ac9a48067090792962d7040f31703e9633fbba0d497e07
|
|
| MD5 |
8781b302094fe5d8c60a6bb42fa55e36
|
|
| BLAKE2b-256 |
86fe40b9910c11fcbe6990e5c46d691690f5bacc19ee668ce2727411b21846dc
|
File details
Details for the file pydoge_api-0.3.0-py3-none-any.whl.
File metadata
- Download URL: pydoge_api-0.3.0-py3-none-any.whl
- Upload date:
- Size: 29.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0629f0bc50c871edfb8a20a6bc8b7e48371e1f932e4250a3b7f4bc8c78d97504
|
|
| MD5 |
4fc6386ccb08702b72093556cc1b585a
|
|
| BLAKE2b-256 |
3b311e0e4ad1f4bd836e23e5c20234118ebeb46e81ba6f71281773af0a604973
|