New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

rfc9457

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rfc9457

Implementation of RFC9457 problems.

  • 0.3.2
  • PyPI
  • Socket score

Maintainers
1

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,
}

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc