Metadata-Version: 2.3
Name: rfc9457
Version: 0.2.3
Summary: Implementation of RFC9457 problems.
Author-email: Daniel Edgecombe <daniel@nrwl.co>
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: exception,handler,webdev
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Internet
Classifier: Topic :: Utilities
Requires-Python: >=3.9
Requires-Dist: multidict==6.0.5
Provides-Extra: dev
Requires-Dist: changelog-gen>=0.12.0; extra == 'dev'
Requires-Dist: pre-commit>=3.7.1; extra == 'dev'
Requires-Dist: pytest-cov>=4.1.0; extra == 'dev'
Requires-Dist: pytest-random-order>=1.1.1; extra == 'dev'
Requires-Dist: pytest>=7.4.4; extra == 'dev'
Requires-Dist: ruff>=0.6.4; extra == 'dev'
Description-Content-Type: text/markdown

# RFC9457 implementation for Python
[![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)
[![ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![image](https://img.shields.io/pypi/v/rfc9457.svg)](https://pypi.org/project/rfc9457/)
[![image](https://img.shields.io/pypi/l/rfc9457.svg)](https://pypi.org/project/rfc9457/)
[![image](https://img.shields.io/pypi/pyversions/rfc9457.svg)](https://pypi.org/project/rfc9457/)
![style](https://github.com/NRWLDev/rfc9457/actions/workflows/style.yml/badge.svg)
![tests](https://github.com/NRWLDev/rfc9457/actions/workflows/tests.yml/badge.svg)
[![codecov](https://codecov.io/gh/NRWLDev/rfc9457/branch/main/graph/badge.svg)](https://codecov.io/gh/NRWLDev/rfc9457)

`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](https://www.rfc-editor.org/rfc/rfc9457.html) spec for use in api
errors.

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

[starlette-problem](https://pypi.org/project/starlette-problem)
[fastapi-problem](https://pypi.org/project/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.

```python
from rfc9457.error import NotFoundProblem


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


UserNotFoundError(
    details="details",
    custom_key="value",
).marshal()
```

```json
{
    "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.

```python
UserNotFoundError(
    details="details",
    custom_key="value",
).marshal(strip_debug=True)
```

```json
{
    "type": "user-not-found",
    "title": "User not found",
    "status": 404,
}
```
