fastapi-problem


Namefastapi-problem JSON
Version 0.11.5 PyPI version JSON
download
home_pageNone
SummaryFastAPI support for RFC9457 problems.
upload_time2025-08-26 08:31:38
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseNone
keywords exception handler starlette webdev
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # FastAPI Problems
[![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/fastapi_problem.svg)](https://pypi.org/project/fastapi-problem/)
[![image](https://img.shields.io/pypi/l/fastapi_problem.svg)](https://pypi.org/project/fastapi-problem/)
[![image](https://img.shields.io/pypi/pyversions/fastapi_problem.svg)](https://pypi.org/project/fastapi-problem/)
![style](https://github.com/NRWLDev/fastapi-problem/actions/workflows/style.yml/badge.svg)
![tests](https://github.com/NRWLDev/fastapi-problem/actions/workflows/tests.yml/badge.svg)
[![codecov](https://codecov.io/gh/NRWLDev/fastapi-problem/branch/main/graph/badge.svg)](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, new_exception_handler


app = fastapi.FastAPI()
eh = new_exception_handler()
add_exception_handler(app, eh)

@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/41/7e/777e6d4e47af524fbd97aa5edaefae16fc0bfc3cfdda2eed7287c241d8e2/fastapi_problem-0.11.5.tar.gz",
    "platform": null,
    "description": "# FastAPI Problems\n[![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)\n[![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)\n[![image](https://img.shields.io/pypi/v/fastapi_problem.svg)](https://pypi.org/project/fastapi-problem/)\n[![image](https://img.shields.io/pypi/l/fastapi_problem.svg)](https://pypi.org/project/fastapi-problem/)\n[![image](https://img.shields.io/pypi/pyversions/fastapi_problem.svg)](https://pypi.org/project/fastapi-problem/)\n![style](https://github.com/NRWLDev/fastapi-problem/actions/workflows/style.yml/badge.svg)\n![tests](https://github.com/NRWLDev/fastapi-problem/actions/workflows/tests.yml/badge.svg)\n[![codecov](https://codecov.io/gh/NRWLDev/fastapi-problem/branch/main/graph/badge.svg)](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, new_exception_handler\n\n\napp = fastapi.FastAPI()\neh = new_exception_handler()\nadd_exception_handler(app, eh)\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.11.5",
    "project_urls": {
        "documentation": "https://nrwldev.github.io/fastapi-problem/",
        "homepage": "https://github.com/NRWLDev/fastapi-problem/"
    },
    "split_keywords": [
        "exception",
        " handler",
        " starlette",
        " webdev"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "8d395d885042a6df37f1c53158364ad59174f10e96b4458a7e12006ae5da37fa",
                "md5": "19c36f0227b0c168ed456f1042feccd6",
                "sha256": "37e7e77eacb5d358cb970b959b30fb3e209c84bcf8a08ca9343aa28700fcea8d"
            },
            "downloads": -1,
            "filename": "fastapi_problem-0.11.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "19c36f0227b0c168ed456f1042feccd6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 9766,
            "upload_time": "2025-08-26T08:31:37",
            "upload_time_iso_8601": "2025-08-26T08:31:37.845574Z",
            "url": "https://files.pythonhosted.org/packages/8d/39/5d885042a6df37f1c53158364ad59174f10e96b4458a7e12006ae5da37fa/fastapi_problem-0.11.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "417e777e6d4e47af524fbd97aa5edaefae16fc0bfc3cfdda2eed7287c241d8e2",
                "md5": "e387d5cf85ac4a23d58ee0409ec75c63",
                "sha256": "22206fa9faf7501637218cee15ae8abd3e0ad728b39c72b7a0642921d27ade93"
            },
            "downloads": -1,
            "filename": "fastapi_problem-0.11.5.tar.gz",
            "has_sig": false,
            "md5_digest": "e387d5cf85ac4a23d58ee0409ec75c63",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 70605,
            "upload_time": "2025-08-26T08:31:38",
            "upload_time_iso_8601": "2025-08-26T08:31:38.881691Z",
            "url": "https://files.pythonhosted.org/packages/41/7e/777e6d4e47af524fbd97aa5edaefae16fc0bfc3cfdda2eed7287c241d8e2/fastapi_problem-0.11.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-26 08:31:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "NRWLDev",
    "github_project": "fastapi-problem",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "fastapi-problem"
}
        
Elapsed time: 1.59030s