Shared API response envelope for FastAPI projects
Project description
pronto-rest
Shared API utilities for FastAPI projects.
What's included
pronto_rest.v1 — stable public API:
ApiResponse[T]— generic response envelope that every endpoint returns. Carries either a typeddatapayload (on success) or anApiError(on failure), never both.ApiError— structured error model with a machine-readablecode, a human-readablemessage, and an optionaldetailsdict.EmptyData— use as thedatatype when an operation succeeds but returns no domain payload.
Installation
pip install pronto-rest
Or, for local development with editable install:
pip install -e ".[dev]"
Usage
from pronto_rest.v1 import ApiResponse, ApiError
# Success response
response = ApiResponse.ok(
data={"id": "123", "name": "Alice"},
operation="create_user",
endpoint="/api/v1/users/create",
)
# Error response
response = ApiResponse.fail(
code="USER_NOT_FOUND",
message="No user with that ID exists.",
operation="get_user",
endpoint="/api/v1/users/123",
details={"user_id": "123"},
)
With FastAPI
from fastapi import APIRouter
from pronto_rest.v1 import ApiResponse, EmptyData
router = APIRouter()
@router.post("/users/create", response_model=ApiResponse[UserOut])
def create_user(body: UserIn) -> ApiResponse[UserOut]:
user = db.create(body)
return ApiResponse.ok(
data=UserOut.model_validate(user),
operation="create_user",
endpoint="/api/v1/users/create",
)
Response envelope shape
Every response shares this envelope:
| Field | Type | Description |
|---|---|---|
api_version |
str |
Always "1.0" |
status |
"success" | "error" |
Outcome of the operation |
correlation_id |
str (UUID) |
Trace ID; echoed from X-Correlation-ID header if present |
timestamp |
datetime |
UTC timestamp of when the response was generated |
operation |
str |
Logical operation name (e.g. create_user) |
endpoint |
str |
Request path (e.g. /api/v1/users/create) |
data |
T | null |
Response payload; null on error |
error |
ApiError | null |
Error details; null on success |
status="success" requires data and forbids error. status="error" requires error and forbids data.
Development
Run tests:
pytest
Versioning
Versions are derived from git tags via hatch-vcs. The file src/pronto_rest/_version.py is auto-generated at build time and is not tracked in version control — the git tag is the source of truth.
To release a new version, tag a commit and build:
git tag v0.2.0
hatch build
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 pronto_rest-0.0.1.tar.gz.
File metadata
- Download URL: pronto_rest-0.0.1.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1eb39fc7ba19c5713e3f83a7661bcae1b0a2bfdd0ba25d9a3f40b8cfab7e9d8
|
|
| MD5 |
f5cf8b336dde0d53393735314bf52e32
|
|
| BLAKE2b-256 |
ae4197ba53594c5792f56eacc627dea3bb00e5b7b8acd76932fe91dbcb8f1feb
|
Provenance
The following attestation bundles were made for pronto_rest-0.0.1.tar.gz:
Publisher:
publish.yml on justTil/pronto-rest
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pronto_rest-0.0.1.tar.gz -
Subject digest:
c1eb39fc7ba19c5713e3f83a7661bcae1b0a2bfdd0ba25d9a3f40b8cfab7e9d8 - Sigstore transparency entry: 1629271240
- Sigstore integration time:
-
Permalink:
justTil/pronto-rest@a91a80e27658abfb7464df615f588773f5019363 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/justTil
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a91a80e27658abfb7464df615f588773f5019363 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pronto_rest-0.0.1-py3-none-any.whl.
File metadata
- Download URL: pronto_rest-0.0.1-py3-none-any.whl
- Upload date:
- Size: 6.3 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 |
28a68c5a5af3d744feb091edc7b7f9527cfee340f8ae510252489302b7e988f5
|
|
| MD5 |
17b33d65fc65e93cd00ec481c2ee170b
|
|
| BLAKE2b-256 |
8a12aa8d278390daf7fdc811235dd701068de90fbeb977738e9db57bf68786e6
|
Provenance
The following attestation bundles were made for pronto_rest-0.0.1-py3-none-any.whl:
Publisher:
publish.yml on justTil/pronto-rest
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pronto_rest-0.0.1-py3-none-any.whl -
Subject digest:
28a68c5a5af3d744feb091edc7b7f9527cfee340f8ae510252489302b7e988f5 - Sigstore transparency entry: 1629271244
- Sigstore integration time:
-
Permalink:
justTil/pronto-rest@a91a80e27658abfb7464df615f588773f5019363 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/justTil
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a91a80e27658abfb7464df615f588773f5019363 -
Trigger Event:
push
-
Statement type: