# FastAPI Problems
[](https://github.com/astral-sh/uv)
[](https://github.com/astral-sh/ruff)
[](https://pypi.org/project/fastapi-problem/)
[](https://pypi.org/project/fastapi-problem/)
[](https://pypi.org/project/fastapi-problem/)


[](https://codecov.io/gh/NRWLDev/fastapi-problem)
`fastapi_problem` is a set of exceptions and handlers for use in fastapi
applications to support easy error management and responses.
Each exception easily marshals to JSON based on the
[RFC9457](https://www.rfc-editor.org/rfc/rfc9457.html) spec for use in api
errors.
Check the [docs](https://nrwldev.github.io/fastapi-problem) 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.
```python
from fastapi_problem.error import NotFoundProblem
class UserNotFoundError(NotFoundProblem):
title = "User not found."
raise UserNotFoundError(detail="detail")
```
```json
{
"type": "user-not-found",
"title": "User not found",
"detail": "detail",
"status": 404,
}
```
## Usage
```python
import fastapi
from fastapi_problem.handler import add_exception_handler
app = fastapi.FastAPI()
add_exception_handler(app)
@app.get("/user")
async def get_user():
raise UserNotFoundError("No user found.")
```
```bash
$ curl localhost:8000/user
{
"type": "user-not-found",
"title": "User not found",
"detail": "No user found.",
"status": 404,
}
```
Raw data
{
"_id": null,
"home_page": null,
"name": "fastapi-problem",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "exception, handler, starlette, webdev",
"author": null,
"author_email": "Daniel Edgecombe <daniel@nrwl.co>",
"download_url": "https://files.pythonhosted.org/packages/98/20/2a1830881892f67f08c5b878602f8d29b7dae6b73e8cc14165576641525b/fastapi_problem-0.10.5.tar.gz",
"platform": null,
"description": "# FastAPI Problems\n[](https://github.com/astral-sh/uv)\n[](https://github.com/astral-sh/ruff)\n[](https://pypi.org/project/fastapi-problem/)\n[](https://pypi.org/project/fastapi-problem/)\n[](https://pypi.org/project/fastapi-problem/)\n\n\n[](https://codecov.io/gh/NRWLDev/fastapi-problem)\n\n`fastapi_problem` is a set of exceptions and handlers for use in fastapi\napplications to support easy error management and responses.\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\nCheck the [docs](https://nrwldev.github.io/fastapi-problem) for more details.\n\n## Custom Errors\n\nSubclassing the convenience classes provide a simple way to consistently raise\nthe same error with detail/extras changing based on the raised context.\n\n```python\nfrom fastapi_problem.error import NotFoundProblem\n\n\nclass UserNotFoundError(NotFoundProblem):\n title = \"User not found.\"\n\nraise UserNotFoundError(detail=\"detail\")\n```\n\n```json\n{\n \"type\": \"user-not-found\",\n \"title\": \"User not found\",\n \"detail\": \"detail\",\n \"status\": 404,\n}\n```\n\n## Usage\n\n```python\nimport fastapi\nfrom fastapi_problem.handler import add_exception_handler\n\n\napp = fastapi.FastAPI()\nadd_exception_handler(app)\n\n@app.get(\"/user\")\nasync def get_user():\n raise UserNotFoundError(\"No user found.\")\n```\n\n```bash\n$ curl localhost:8000/user\n{\n\n \"type\": \"user-not-found\",\n \"title\": \"User not found\",\n \"detail\": \"No user found.\",\n \"status\": 404,\n}\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "FastAPI support for RFC9457 problems.",
"version": "0.10.5",
"project_urls": null,
"split_keywords": [
"exception",
" handler",
" starlette",
" webdev"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "2e4f59346d1cb49fed4779a4b7d33be937ea8eca9e7312b8fab61b4c45c93fba",
"md5": "2971b6efe78a07cb28db9030707150a4",
"sha256": "5c336d50e3f0c0922d84a9c6a8f748589be36adf1602b20215d4d03e4d62d2b5"
},
"downloads": -1,
"filename": "fastapi_problem-0.10.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2971b6efe78a07cb28db9030707150a4",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 9236,
"upload_time": "2025-02-07T16:54:53",
"upload_time_iso_8601": "2025-02-07T16:54:53.333433Z",
"url": "https://files.pythonhosted.org/packages/2e/4f/59346d1cb49fed4779a4b7d33be937ea8eca9e7312b8fab61b4c45c93fba/fastapi_problem-0.10.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "98202a1830881892f67f08c5b878602f8d29b7dae6b73e8cc14165576641525b",
"md5": "8be57df4edb1f1c9499c2c4862b28ef8",
"sha256": "4d38c3c3e734c7eadc35ede47a342cb6790f4158ff7a92b07d696bce73748bbd"
},
"downloads": -1,
"filename": "fastapi_problem-0.10.5.tar.gz",
"has_sig": false,
"md5_digest": "8be57df4edb1f1c9499c2c4862b28ef8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 68091,
"upload_time": "2025-02-07T16:54:54",
"upload_time_iso_8601": "2025-02-07T16:54:54.994131Z",
"url": "https://files.pythonhosted.org/packages/98/20/2a1830881892f67f08c5b878602f8d29b7dae6b73e8cc14165576641525b/fastapi_problem-0.10.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-07 16:54:54",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "fastapi-problem"
}