starlette-problem


Namestarlette-problem JSON
Version 0.11.3 PyPI version JSON
download
home_pageNone
SummaryStarlette support for RFC9457 problems.
upload_time2024-11-25 11:55:31
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseApache-2.0
keywords exception handler starlette webdev
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Starlette 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/starlette_problem.svg)](https://pypi.org/project/starlette-problem/)
[![image](https://img.shields.io/pypi/l/starlette_problem.svg)](https://pypi.org/project/starlette-problem/)
[![image](https://img.shields.io/pypi/pyversions/starlette_problem.svg)](https://pypi.org/project/starlette-problem/)
![style](https://github.com/NRWLDev/starlette-problem/actions/workflows/style.yml/badge.svg)
![tests](https://github.com/NRWLDev/starlette-problem/actions/workflows/tests.yml/badge.svg)
[![codecov](https://codecov.io/gh/NRWLDev/starlette-problem/branch/main/graph/badge.svg)](https://codecov.io/gh/NRWLDev/starlette-problem)

`starlette_problem` is a set of exceptions and handlers for use in starlette
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/starlette-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 starlette_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 starlette.applications
from starlette_problem.handler import add_exception_handler


app = starlette.applications.Starlette()
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": "starlette-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/12/d7/150d5d52a0156e41bb8d93e243bc6452244c743f0f1916eca62f61f8dd85/starlette_problem-0.11.3.tar.gz",
    "platform": null,
    "description": "# Starlette 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/starlette_problem.svg)](https://pypi.org/project/starlette-problem/)\n[![image](https://img.shields.io/pypi/l/starlette_problem.svg)](https://pypi.org/project/starlette-problem/)\n[![image](https://img.shields.io/pypi/pyversions/starlette_problem.svg)](https://pypi.org/project/starlette-problem/)\n![style](https://github.com/NRWLDev/starlette-problem/actions/workflows/style.yml/badge.svg)\n![tests](https://github.com/NRWLDev/starlette-problem/actions/workflows/tests.yml/badge.svg)\n[![codecov](https://codecov.io/gh/NRWLDev/starlette-problem/branch/main/graph/badge.svg)](https://codecov.io/gh/NRWLDev/starlette-problem)\n\n`starlette_problem` is a set of exceptions and handlers for use in starlette\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/starlette-problem) for more details.\n\n## Custom Errors\n\nSubclassing the convenience classes provide a simple way to consistently raise the same error\nwith detail/extras changing based on the raised context.\n\n```python\nfrom starlette_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 starlette.applications\nfrom starlette_problem.handler import add_exception_handler\n\n\napp = starlette.applications.Starlette()\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": "Apache-2.0",
    "summary": "Starlette support for RFC9457 problems.",
    "version": "0.11.3",
    "project_urls": null,
    "split_keywords": [
        "exception",
        " handler",
        " starlette",
        " webdev"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e8c631deccf950f76a81778ca35540c0c18fbd0636acbca40d49ac629680d6a6",
                "md5": "60aa83a6ba9a4d2c0494fcfcdace446e",
                "sha256": "79f4d4d556fec7c87799e43736483b1c6d20a37e576cfa1340116a78cfca64bd"
            },
            "downloads": -1,
            "filename": "starlette_problem-0.11.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "60aa83a6ba9a4d2c0494fcfcdace446e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 10268,
            "upload_time": "2024-11-25T11:55:30",
            "upload_time_iso_8601": "2024-11-25T11:55:30.235958Z",
            "url": "https://files.pythonhosted.org/packages/e8/c6/31deccf950f76a81778ca35540c0c18fbd0636acbca40d49ac629680d6a6/starlette_problem-0.11.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "12d7150d5d52a0156e41bb8d93e243bc6452244c743f0f1916eca62f61f8dd85",
                "md5": "f824f54e330128a8e2bccec38e3c0add",
                "sha256": "2d3b5dac335b6753b24661c14087303a13a732b7349747a1a2d96441b7a85f45"
            },
            "downloads": -1,
            "filename": "starlette_problem-0.11.3.tar.gz",
            "has_sig": false,
            "md5_digest": "f824f54e330128a8e2bccec38e3c0add",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 59588,
            "upload_time": "2024-11-25T11:55:31",
            "upload_time_iso_8601": "2024-11-25T11:55:31.778603Z",
            "url": "https://files.pythonhosted.org/packages/12/d7/150d5d52a0156e41bb8d93e243bc6452244c743f0f1916eca62f61f8dd85/starlette_problem-0.11.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-25 11:55:31",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "starlette-problem"
}
        
Elapsed time: 0.43372s