Name | rfc9457 JSON |
Version |
0.3.2
JSON |
| download |
home_page | None |
Summary | Implementation of RFC9457 problems. |
upload_time | 2025-02-17 17:13:43 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | None |
keywords |
exception
handler
webdev
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# RFC9457 implementation for Python
[](https://github.com/astral-sh/uv)
[](https://github.com/astral-sh/ruff)
[](https://pypi.org/project/rfc9457/)
[](https://pypi.org/project/rfc9457/)
[](https://pypi.org/project/rfc9457/)


[](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,
}
```
Raw data
{
"_id": null,
"home_page": null,
"name": "rfc9457",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "exception, handler, webdev",
"author": null,
"author_email": "Daniel Edgecombe <daniel@nrwl.co>",
"download_url": "https://files.pythonhosted.org/packages/2e/27/673e5ba7eb9b8bb1a372530675e71ceef848284a978043987bc7affc820b/rfc9457-0.3.2.tar.gz",
"platform": null,
"description": "# RFC9457 implementation for Python\n[](https://github.com/astral-sh/uv)\n[](https://github.com/astral-sh/ruff)\n[](https://pypi.org/project/rfc9457/)\n[](https://pypi.org/project/rfc9457/)\n[](https://pypi.org/project/rfc9457/)\n\n\n[](https://codecov.io/gh/NRWLDev/rfc9457)\n\n`rfc9457` is a set of exceptions to support easy error management and responses\nin web based apis.\n\nEach exception easily marshals to JSON based on the\n[RFC9457](https://www.rfc-editor.org/rfc/rfc9457.html) spec for use in api\nerrors.\n\nThis library is currently used to support problem details in both Starlette and FastAPI.\n\n[starlette-problem](https://pypi.org/project/starlette-problem)\n[fastapi-problem](https://pypi.org/project/fastapi-problem)\n\n## Custom Errors\n\nSubclassing the convenience classes provides a simple way to consistently raise\nthe same error with details/extras changing based on the raised context.\n\n```python\nfrom rfc9457.error import NotFoundProblem\n\n\nclass UserNotFoundError(NotFoundProblem):\n title = \"User not found.\"\n\n\nUserNotFoundError(\n details=\"details\",\n custom_key=\"value\",\n).marshal()\n```\n\n```json\n{\n \"type\": \"user-not-found\",\n \"title\": \"User not found\",\n \"status\": 404,\n \"details\": \"details\",\n \"custom_key\": \"value\",\n}\n```\n\n## Removing debug information in production\n\nIn production environments, it may be desirable to exclude per instance\ninformation to prevent data leakage. In that scenario use `strip_debug` when\nmarshaling the error.\n\n```python\nUserNotFoundError(\n details=\"details\",\n custom_key=\"value\",\n).marshal(strip_debug=True)\n```\n\n```json\n{\n \"type\": \"user-not-found\",\n \"title\": \"User not found\",\n \"status\": 404,\n}\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "Implementation of RFC9457 problems.",
"version": "0.3.2",
"project_urls": null,
"split_keywords": [
"exception",
" handler",
" webdev"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "97f9c8ae05e89e6351285ac77e95db0b5c694f1ade3ba60b5c9d79b48d794978",
"md5": "91ecbe1a620f8bce7abc108c4c74c751",
"sha256": "b3b857440ccf0962d91456aad1c76eb0f3582b8c783da23e983cfd7232901820"
},
"downloads": -1,
"filename": "rfc9457-0.3.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "91ecbe1a620f8bce7abc108c4c74c751",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 8078,
"upload_time": "2025-02-17T17:13:42",
"upload_time_iso_8601": "2025-02-17T17:13:42.001665Z",
"url": "https://files.pythonhosted.org/packages/97/f9/c8ae05e89e6351285ac77e95db0b5c694f1ade3ba60b5c9d79b48d794978/rfc9457-0.3.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "2e27673e5ba7eb9b8bb1a372530675e71ceef848284a978043987bc7affc820b",
"md5": "91d0586d15719195b47007d7804b823c",
"sha256": "fb1dc624e45ccd922b94fcf7151cb77549d6be4505c0702acc7bb92214c01558"
},
"downloads": -1,
"filename": "rfc9457-0.3.2.tar.gz",
"has_sig": false,
"md5_digest": "91d0586d15719195b47007d7804b823c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 46967,
"upload_time": "2025-02-17T17:13:43",
"upload_time_iso_8601": "2025-02-17T17:13:43.999691Z",
"url": "https://files.pythonhosted.org/packages/2e/27/673e5ba7eb9b8bb1a372530675e71ceef848284a978043987bc7affc820b/rfc9457-0.3.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-17 17:13:43",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "rfc9457"
}