starlette-ras-handle


Namestarlette-ras-handle JSON
Version 1.0.1 PyPI version JSON
download
home_pageNone
SummaryThis library patches starlette, so you can handle "RuntimeError: Caught handled exception, but response already started." exception
upload_time2024-04-14 19:04:36
maintainerNone
docs_urlNone
authorsushka
requires_python<4.0,>=3.10
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">

# Starlette RAS-handler

[![Supported Python versions](https://img.shields.io/pypi/pyversions/starlette-ras-handle.svg?logo=python&logoColor=FFE873)](https://pypi.org/project/starlette-ras-handle)
[![PyPI version](https://img.shields.io/pypi/v/starlette-ras-handle.svg?logo=pypi&logoColor=FFE873)](https://pypi.org/project/starlette-ras-handle)
[![PyPI downloads](https://img.shields.io/pypi/dm/starlette-ras-handle.svg)](https://pypi.org/project/starlette-ras-handle)

</div>

This library adds the ability to handle `RuntimeError: Caught handled exception, but response already started.` error, so you can silent it, or do whatever you want

## Installation 📥

```shell
python -m pip install -U starlette-ras-handle 
```


## Usage 🛠️
1. Define an async function that accepts `(Exception, Request | WebSocket)` and returns `None`
    ```python
    async def print_handler(exc: Exception, request: Request | WebSocket) -> None:
        print("Caught", exc)
    ```

2. Patch!
    ```python
    from handler import print_handler
    
    from starlette_ras_handle import handle_starlette_ras
    handle_starlette_ras(print_handler)
    
    # other imports...
    ```
   
**IMPORTANT:** If you want the patch to work properly, you should use it before you import anything, related to `starlette` (e.g. `FastAPI`)

You can check an example in `/examples/example.py`

## Troubleshooting 🚨

If you encounter issues or have queries, feel free to check our [Issues section](https://github.com/barabum0/starlette-ras-handle/issues) on GitHub.

## Contribution 🤝

Contributions are welcome. Please fork the repository, make your changes, and submit a pull request.
            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "starlette-ras-handle",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": "sushka",
    "author_email": "r.m.poltorabatko@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/43/d5/f37dcb2bbb2f5b46dcf44b16930bc15c90e75b3aa5d97118abd1690e5fc1/starlette_ras_handle-1.0.1.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\n\n# Starlette RAS-handler\n\n[![Supported Python versions](https://img.shields.io/pypi/pyversions/starlette-ras-handle.svg?logo=python&logoColor=FFE873)](https://pypi.org/project/starlette-ras-handle)\n[![PyPI version](https://img.shields.io/pypi/v/starlette-ras-handle.svg?logo=pypi&logoColor=FFE873)](https://pypi.org/project/starlette-ras-handle)\n[![PyPI downloads](https://img.shields.io/pypi/dm/starlette-ras-handle.svg)](https://pypi.org/project/starlette-ras-handle)\n\n</div>\n\nThis library adds the ability to handle `RuntimeError: Caught handled exception, but response already started.` error, so you can silent it, or do whatever you want\n\n## Installation \ud83d\udce5\n\n```shell\npython -m pip install -U starlette-ras-handle \n```\n\n\n## Usage \ud83d\udee0\ufe0f\n1. Define an async function that accepts `(Exception, Request | WebSocket)` and returns `None`\n    ```python\n    async def print_handler(exc: Exception, request: Request | WebSocket) -> None:\n        print(\"Caught\", exc)\n    ```\n\n2. Patch!\n    ```python\n    from handler import print_handler\n    \n    from starlette_ras_handle import handle_starlette_ras\n    handle_starlette_ras(print_handler)\n    \n    # other imports...\n    ```\n   \n**IMPORTANT:** If you want the patch to work properly, you should use it before you import anything, related to `starlette` (e.g. `FastAPI`)\n\nYou can check an example in `/examples/example.py`\n\n## Troubleshooting \ud83d\udea8\n\nIf you encounter issues or have queries, feel free to check our [Issues section](https://github.com/barabum0/starlette-ras-handle/issues) on GitHub.\n\n## Contribution \ud83e\udd1d\n\nContributions are welcome. Please fork the repository, make your changes, and submit a pull request.",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "This library patches starlette, so you can handle \"RuntimeError: Caught handled exception, but response already started.\" exception",
    "version": "1.0.1",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3b38006ee2723875eb25c9dbd0f65b9ce69684f2e11ea0ffd79f42635f3d1de9",
                "md5": "e14083d30aa725c0b93fdc4598928936",
                "sha256": "3212d631817136b79139b1551db50da985f8098021c67c05893c87d2e67fc8b6"
            },
            "downloads": -1,
            "filename": "starlette_ras_handle-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e14083d30aa725c0b93fdc4598928936",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 3643,
            "upload_time": "2024-04-14T19:04:34",
            "upload_time_iso_8601": "2024-04-14T19:04:34.779719Z",
            "url": "https://files.pythonhosted.org/packages/3b/38/006ee2723875eb25c9dbd0f65b9ce69684f2e11ea0ffd79f42635f3d1de9/starlette_ras_handle-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "43d5f37dcb2bbb2f5b46dcf44b16930bc15c90e75b3aa5d97118abd1690e5fc1",
                "md5": "ed052e4230ef9c41f0ce9097d7e7ddac",
                "sha256": "62ed64da9308060d249f23a6aae3a7fabc93fc8040db2e5fc6d7324d89a98a7a"
            },
            "downloads": -1,
            "filename": "starlette_ras_handle-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "ed052e4230ef9c41f0ce9097d7e7ddac",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 3099,
            "upload_time": "2024-04-14T19:04:36",
            "upload_time_iso_8601": "2024-04-14T19:04:36.621432Z",
            "url": "https://files.pythonhosted.org/packages/43/d5/f37dcb2bbb2f5b46dcf44b16930bc15c90e75b3aa5d97118abd1690e5fc1/starlette_ras_handle-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-14 19:04:36",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "starlette-ras-handle"
}
        
Elapsed time: 0.20914s