Skip to main content

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 typed data payload (on success) or an ApiError (on failure), never both.
  • ApiError — structured error model with a machine-readable code, a human-readable message, and an optional details dict.
  • EmptyData — use as the data type 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


Download files

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

Source Distribution

pronto_rest-0.0.1.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

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

pronto_rest-0.0.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

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

Hashes for pronto_rest-0.0.1.tar.gz
Algorithm Hash digest
SHA256 c1eb39fc7ba19c5713e3f83a7661bcae1b0a2bfdd0ba25d9a3f40b8cfab7e9d8
MD5 f5cf8b336dde0d53393735314bf52e32
BLAKE2b-256 ae4197ba53594c5792f56eacc627dea3bb00e5b7b8acd76932fe91dbcb8f1feb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pronto_rest-0.0.1.tar.gz:

Publisher: publish.yml on justTil/pronto-rest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for pronto_rest-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 28a68c5a5af3d744feb091edc7b7f9527cfee340f8ae510252489302b7e988f5
MD5 17b33d65fc65e93cd00ec481c2ee170b
BLAKE2b-256 8a12aa8d278390daf7fdc811235dd701068de90fbeb977738e9db57bf68786e6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pronto_rest-0.0.1-py3-none-any.whl:

Publisher: publish.yml on justTil/pronto-rest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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