Historical document. This is the design written before the library was built. Parts of it are out of date (for example it rules out a command line and lists names that changed). The code, the README and
docs/reference/describe what the library does today.
A Python client library for the EEA Reportnet 3 REST API (api.reportnet.europa.eu),
generated from the project's Swagger 2.0 spec (api-docs.json, 62 endpoints / 49
model definitions across 6 tags). The library wraps raw HTTP calls with a typed,
ergonomic, resource-namespaced client for both sync and async usage.
Source spec snapshot: spec/api-docs.json (Swagger 2.0, host api.reportnet.europa.eu,
JWT bearer auth via Authorization header).
In scope:
- Full coverage of all 62 endpoints across the 6 tags:
- Dataset Schema (11 endpoints)
- Datasets (42 endpoints)
- Dataset Snapshot (7 endpoints)
- EU Datasets (1 endpoint)
- Release Receipts (4 endpoints)
- Pydantic v2 models for all 49 swagger definitions.
- Sync and async clients sharing one HTTP core.
- File upload/download support (attachments, CSV/Parquet export, importFileData).
Out of scope (v1):
- No login/token-acquisition flow — the caller supplies a valid JWT or a callable that returns one.
- No CLI.
- No response caching.
reportnet_api/
├── __init__.py
├── _core.py # shared request-building/transport logic
├── _auth.py # token / token-provider handling
├── _exceptions.py # exception hierarchy
├── client.py # ReportnetClient (sync)
├── async_client.py # AsyncReportnetClient
├── models/ # Pydantic models, generated from swagger definitions
│ ├── __init__.py
│ └── generated.py
└── resources/ # one module per swagger tag
├── __init__.py
├── dataset_schema.py
├── datasets.py
├── dataset_snapshot.py
├── eu_datasets.py
└── release_receipts.py
Usage shape:
from reportnet_api import ReportnetClient
client = ReportnetClient(base_url="https://api.reportnet.europa.eu", token="...")
schema = client.dataset_schema.find_data_schema_by_dataset_id(dataset_id=...)
client.datasets.import_file_data(dataset_id=123, file="path/to/file.csv", ...)Async mirrors this 1:1 with await:
from reportnet_api import AsyncReportnetClient
client = AsyncReportnetClient(base_url="...", token="...")
schema = await client.dataset_schema.find_data_schema_by_dataset_id(...)- Built on
httpx. One shared module (_core.py) builds requests (URL, params, headers, body) from method-level metadata;client.pyandasync_client.pyare thin wrappers callinghttpx.Client/httpx.AsyncClientrespectively. - No endpoint's request-building logic should be written twice for sync/async.
ReportnetClient(token="...")accepts either a static string or a zero-arg callable (token_provider) so callers can plug in their own refresh logic.- Every request attaches
Authorization: <scheme> <token>, where<scheme>defaults toBearerbut is overridable viatoken_scheme=— Reportnet's dataflow-scoped API keys useAuthorization: ApiKey <key>instead of a JWT bearer token, so the scheme isn't fixed. - No login endpoint is implemented — none exists in the swagger spec.
- All 49 definitions in
api-docs.json#/definitionsare converted to Pydantic v2 models viadatamodel-code-generator, output tomodels/generated.py. - Regeneration is a scripted, repeatable step (see
scripts/), not a one-time hand-edit — if the spec changes, models regenerate cleanly. - Hand-written model subclasses/helpers (if needed for ergonomics) live outside
generated.pyso regeneration never clobbers them.
- A custom generator script (
scripts/generate_resources.py) parsesapi-docs.jsonand emits one method per operation into the appropriateresources/<tag>.pyfile, grouped by swaggertags. - Each generated method: typed params (from path/query/body parameters), typed
return (from the
200response schema where available), and a docstring pulled from the operation'ssummary/description. - Endpoints with duplicate versions (
etlExportv1/v2/v3,importFileDatav1/v2/v3 under/dataset/{version}/...) are all exposed as separate methods (e.g.export_etl_v1,export_etl_v2,export_etl_v3); older versions are markedDeprecated: use export_etl_v3 instead.in the docstring, not removed. - Manual review pass after generation focuses on: naming consistency, docstring quality, and correctness of file-upload/download endpoints (these need special handling the generic generator won't get right automatically).
- Interface is path-based streaming, not in-memory bytes:
- Upload:
client.datasets.import_file_data(dataset_id=..., file="local/path.csv", ...) - Download:
client.snapshot.download_historic_releases(dataset_id=..., dest="local/out.csv")
- Upload:
- Implemented via
httpx's streaming request/response support so large files aren't fully buffered in memory.
Custom exception hierarchy, mapped from HTTP status codes:
ReportnetAPIError (base)
├── AuthenticationError # 401
├── ForbiddenError # 403
├── NotFoundError # 404
├── ValidationError # 400 / 422 if applicable
└── ServerError # 5xx
All exceptions carry status_code, response_body, and the originating
httpx.Request/httpx.Response for debugging. Unmapped status codes raise the
base ReportnetAPIError.
- Packaging:
uv+hatchling,pyproject.toml-only (nosetup.py). - Lint/format:
ruff. - Type checking:
mypy(strict onreportnet_api/, relaxed on generated code if needed). - Testing:
pytest+respx(orpytest-httpx) for mocked HTTP — no live calls to the real API in CI. - CI: GitHub Actions workflow running ruff → mypy → pytest on every push/PR.
- Rate limiting / retry policy: not decided yet, revisit once real usage patterns are known (Datasets tag alone has 42 endpoints, likely a mix of read-heavy and write-heavy calls).
- Pagination helpers (
limit/offsetappear onetlExportendpoints only) — v1 will exposelimit/offsetas plain params; auto-pagination iterators are a possible v2 addition. - PyPI publishing — not scoped for v1; local/
uv addfrom git is sufficient initially.