Skip to main content

Starlette Problems

uv ruff image image image style tests codecov

starlette_problem is a set of exceptions and handlers for use in starlette applications to support easy error management and responses.

Each exception easily marshals to JSON based on the RFC9457 spec for use in api errors.

Check the docs for more details.

Custom Errors

Subclassing the convenience classes provide a simple way to consistently raise the same error with detail/extras changing based on the raised context.

from starlette_problem.error import NotFoundProblem


class UserNotFoundError(NotFoundProblem):
    title = "User not found."

raise UserNotFoundError(detail="detail")
{
    "type": "user-not-found",
    "title": "User not found",
    "detail": "detail",
    "status": 404,
}

Usage

import starlette.applications
from starlette_problem.handler import add_exception_handler


app = starlette.applications.Starlette()
add_exception_handler(app)

@app.get("/user")
async def get_user():
    raise UserNotFoundError("No user found.")
$ curl localhost:8000/user
{

    "type": "user-not-found",
    "title": "User not found",
    "detail": "No user found.",
    "status": 404,
}

Metadata

Release files for starlette-problem 0.13.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for starlette-problem 0.13.5
File Size Uploaded
starlette_problem-0.13.5.tar.gz 83.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for starlette-problem 0.13.5
File Interpreter ABI Platform
starlette_problem-0.13.5-py3-none-any.whl Python 3 none any Details

Total release size: 94.7 kB

Release files / starlette_problem-0.13.5.tar.gz

Download URL starlette_problem-0.13.5.tar.gz
Size 83.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f7839f1692971b0de77ee04c9df1c02afff841e8f47abea7f2ef54359ef2408e
BLAKE2b-256 checksum
How to use checksums
89e0fa662f593314824e5a62b57e929e60b42050b53646c2a21bf93f9894e643
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / starlette_problem-0.13.5-py3-none-any.whl

Download URL starlette_problem-0.13.5-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3fa1f19141ac675dcbcefd1871bd52beeccf7c3375ce162931f6a82fd8707b70
BLAKE2b-256 checksum
How to use checksums
becce36cf52424ea3142e7b38de6ce3fe416f63173d2e18325cb1e682dda21f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page