Skip to main content

Implementation of RFC9457 problems.

Project description

RFC9457 implementation for Python

uv ruff image image image style tests codecov

rfc9457 is a set of exceptions to support easy error management and responses in web based apis.

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

This library is currently used to support problem details in both Starlette and FastAPI.

starlette-problem fastapi-problem

Custom Errors

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

from rfc9457.error import NotFoundProblem


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


UserNotFoundError(
    details="details",
    custom_key="value",
).marshal()
{
    "type": "user-not-found",
    "title": "User not found",
    "status": 404,
    "details": "details",
    "custom_key": "value",
}

Removing debug information in production

In production environments, it may be desirable to exclude per instance information to prevent data leakage. In that scenario use strip_debug when marshaling the error.

UserNotFoundError(
    details="details",
    custom_key="value",
).marshal(strip_debug=True)
{
    "type": "user-not-found",
    "title": "User not found",
    "status": 404,
}

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

rfc9457-0.3.0.tar.gz (46.9 kB view details)

Uploaded Source

Built Distribution

rfc9457-0.3.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file rfc9457-0.3.0.tar.gz.

File metadata

  • Download URL: rfc9457-0.3.0.tar.gz
  • Upload date:
  • Size: 46.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for rfc9457-0.3.0.tar.gz
Algorithm Hash digest
SHA256 11da4d262050d955db8141bd10135cb2872d71f6efb8bbd284d846d423ac9a32
MD5 882c6e64fd48327241ad11b5d54d4ec8
BLAKE2b-256 ff06b1f8b531aa7ccfc4dce667584ec6b285dc8510f39ba26c79882554100cdd

See more details on using hashes here.

File details

Details for the file rfc9457-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: rfc9457-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for rfc9457-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6bea7e8e039d7dbaff38572efa248a05eb554dc8b724c74bb01e11a82e271fe8
MD5 3cb02c68936024d1b1d6a18cd98e0bd2
BLAKE2b-256 8e26ca9f42fe017df4c885a6afc2d4a2f881523d0cace7d453745b083dc63155

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page