Python SDK for the Congress.gov API — models, middleware services, and generated HTTP client
Project description
congressgov
Python SDK for the Congress.gov API — typed Pydantic models, high-level services, and query extensions.
Community client for the official Congress.gov API specification (not affiliated with the Library of Congress). PyPI package: congressgov · This repo: congressgov-python
Features
- Typed models — Pydantic validation for bills, members, committees, and more
- Middleware services —
Bill,Member,Committee, and 15+ other resource classes - Query extensions —
get_actions(),filter(),group_by(), and chainable queries on collections - Async — parallel
AsyncBill,AsyncMember, … undercongressgov.async_api
Requirements
- Python 3.13+
- A free Congress.gov API key
Installation
pip install congressgov
Full install (all optional runtime features):
pip install congressgov[all]
From source (development):
git clone https://github.com/CMD0112/congressgov-python.git
cd congressgov-python
poetry install --with dev,cache,export,batch
# Or: pip install -e ".[dev,all]"
API key
cp .env.example .env
# Set CONGRESS_API_KEY=your-key-here
Or export CONGRESS_API_KEY in your shell. The library reads it via get_client_from_env().
Quick start
from congressgov import Bill, get_client_from_env
client = get_client_from_env()
bill = Bill(client=client).get(congress=118, bill_type="hr", bill_number=1)
print(bill.title)
print(len(bill.get_actions() or []), "actions")
Run the sample scripts (with CONGRESS_API_KEY set):
poetry run python examples/quickstart.py
poetry run python examples/quickstart_async.py
Async
from congressgov.async_api import AsyncBill
bill = await AsyncBill(client=client).get(
congress=118, bill_type="hr", bill_number=1
)
Architecture
flowchart TB
subgraph app [Your application]
UserCode[Your code]
end
subgraph sdk [congressgov SDK]
Facade[congressgov facade]
MW[middleware services]
MD[models]
CL[congress_gov_api_client]
end
API[Congress.gov API v3]
UserCode --> Facade
Facade --> MW
MW --> MD
MW --> CL
CL --> API
| Layer | Import | Role |
|---|---|---|
| Facade | congressgov |
Canonical public API (Bill, Member, …) |
| Services | middleware (legacy) |
Same services; deprecated in 1.1, removal in 2.0 |
| Models | models |
Parsed, validated data |
| Client | congressgov.client or congress_gov_api_client |
Generated HTTP calls |
Optional features
Caching, batch jobs, export, and rate limiting require optional extras (lazy-imported from congressgov):
| Extra | Install | Enables |
|---|---|---|
cache |
pip install congressgov[cache] |
CachedBill, RedisCache, RateLimiter, … |
export |
pip install congressgov[export] |
DataExporter, PandasIntegration, … |
batch |
pip install congressgov[batch] |
BatchProcessor, … |
all |
pip install congressgov[all] |
All of the above |
codegen |
pip install congressgov[codegen] |
Maintainer deps only; run python -m codegen from a git clone |
viz |
pip install congressgov[viz] |
Matplotlib helpers in export visualization |
Details: docs/ADVANCED.md. Architecture: docs/ARCHITECTURE.md.
Regenerating from OpenAPI
The committed client and models are generated from codegen/config/openapi_spec.yaml. To regenerate after spec changes:
poetry install --with codegen
poetry run python -m codegen validate-spec
poetry run python -m codegen generate-all
Stepwise: python -m codegen generate-client, generate-models, generate-middleware.
- Spec:
codegen/config/openapi_spec.yaml - Config:
codegen/config/generator_config.yaml - Incremental mode preserves
# CUSTOM:blocks in generated files - Do not overwrite hand-maintained
middleware/async_api/bill.pyandcached_bill.py
Full workflow: docs/CODEGEN.md
Documentation
| Guide | Contents |
|---|---|
| docs/USAGE.md | Getting started, async, errors, congressional record types |
| docs/MIGRATION.md | Import path changes (1.1 → 2.0) |
| docs/VERSIONING.md | SemVer, deprecations, stability scope |
| docs/REFERENCE.md | Services, client, models, extensions |
| docs/ADVANCED.md | Caching, batch, export, rate limits |
| docs/ARCHITECTURE.md | Core vs extras, generated vs hand-maintained |
| docs/CODEGEN.md | OpenAPI code generation (maintainers) |
| docs/PUBLISHING.md | PyPI trusted publishing (maintainers) |
| docs/API_COVERAGE.md | OpenAPI path coverage matrix (maintainers) |
Contributing
See CONTRIBUTING.md. Security: SECURITY.md. Releases: CHANGELOG.md.
License
Project details
Release history Release notifications | RSS feed
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 congressgov-1.1.0.tar.gz.
File metadata
- Download URL: congressgov-1.1.0.tar.gz
- Upload date:
- Size: 528.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d75f0b3d8579ac6451755eb9056f64bce64b886e19cf7e4677d6c12bc66f798d
|
|
| MD5 |
23328264af91dea2276f8570f8cc4761
|
|
| BLAKE2b-256 |
a277693ee3b9a74a14d6bb1299fc8bcffa60c3968be5416e4be977f2c6913037
|
Provenance
The following attestation bundles were made for congressgov-1.1.0.tar.gz:
Publisher:
publish.yml on CMD0112/congressgov-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
congressgov-1.1.0.tar.gz -
Subject digest:
d75f0b3d8579ac6451755eb9056f64bce64b886e19cf7e4677d6c12bc66f798d - Sigstore transparency entry: 1577131219
- Sigstore integration time:
-
Permalink:
CMD0112/congressgov-python@426f54b5616595cf82ca3fce2a186e055c92d239 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/CMD0112
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@426f54b5616595cf82ca3fce2a186e055c92d239 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file congressgov-1.1.0-py3-none-any.whl.
File metadata
- Download URL: congressgov-1.1.0-py3-none-any.whl
- Upload date:
- Size: 938.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b46af8f8c7eb11e3c2c66faf74d1181cabb65ee49863a4708c4f4e8ec205def
|
|
| MD5 |
49f9a49cb9844bfb288ac119dc589735
|
|
| BLAKE2b-256 |
0d8f9ff9844bb63901c67743f3cfdfcff8713e5c1870cd21969747f99e7b92d6
|
Provenance
The following attestation bundles were made for congressgov-1.1.0-py3-none-any.whl:
Publisher:
publish.yml on CMD0112/congressgov-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
congressgov-1.1.0-py3-none-any.whl -
Subject digest:
5b46af8f8c7eb11e3c2c66faf74d1181cabb65ee49863a4708c4f4e8ec205def - Sigstore transparency entry: 1577131610
- Sigstore integration time:
-
Permalink:
CMD0112/congressgov-python@426f54b5616595cf82ca3fce2a186e055c92d239 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/CMD0112
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@426f54b5616595cf82ca3fce2a186e055c92d239 -
Trigger Event:
workflow_dispatch
-
Statement type: