python-middlewareable


Namepython-middlewareable JSON
Version 1.0.0 PyPI version JSON
download
home_pageNone
SummaryA simple library for working with middlewares in Python
upload_time2024-09-17 17:35:09
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseThe MIT License (MIT) Copyright (c) 2024 TheCodeCrate <loureiro.rg@gmail.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords middleware python library request-handling python-middleware
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Python-Middlewareable

A simple library for working with middlewares in Python.

## Installation

```bash
pip install python-middlewareable
```

## Usage

### 1. Define the payload structure

```python
@dataclass
class Request(RequestBase): # inherit from RequestBase
    name: str
```

### 2. Create a middleware

```python
class OneMiddleware(MiddlewareBase[Request]):
    async def handle(
        self, request: Request, next_call: MiddlewareNextCallBase[Request]
    ) -> None:
        request.name = request.name + " from OneMiddleware"

        print("OneMiddleware before")
        await next_call(request)
        print("OneMiddleware after")

```

### 3. Add the `MiddlewareableBase` trait to the class that will use the middlewares

```python
class App(MiddlewareableBase[Request]):
    middlewares = [OneMiddleware] # add your middlewares here
```

### 4. Instantiate and use it

```python
# middlewareable
app = App()

# process request
result = await app.process_middlewares(Request(name="Hello"))

# check the result
print(request)

# output:
# OneMiddleware before
# OneMiddleware after
# Hello from OneMiddleware
```

## Traits

You can use the following traits to extend the functionality of your classes:

- [AutoInstantiable](src/python_middlewareable/traits/auto_instantiable)
- [DataStructurable](src/python_middlewareable/traits/data_structurable)

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "python-middlewareable",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "middleware, python, library, request-handling, python-middleware",
    "author": null,
    "author_email": "TheCodeCrate <loureiro.rg@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/bb/c2/f37d47f16c009ed5e702ec8dff2baa391758fe36a4e4ba9f917e3f57c050/python_middlewareable-1.0.0.tar.gz",
    "platform": null,
    "description": "# Python-Middlewareable\n\nA simple library for working with middlewares in Python.\n\n## Installation\n\n```bash\npip install python-middlewareable\n```\n\n## Usage\n\n### 1. Define the payload structure\n\n```python\n@dataclass\nclass Request(RequestBase): # inherit from RequestBase\n    name: str\n```\n\n### 2. Create a middleware\n\n```python\nclass OneMiddleware(MiddlewareBase[Request]):\n    async def handle(\n        self, request: Request, next_call: MiddlewareNextCallBase[Request]\n    ) -> None:\n        request.name = request.name + \" from OneMiddleware\"\n\n        print(\"OneMiddleware before\")\n        await next_call(request)\n        print(\"OneMiddleware after\")\n\n```\n\n### 3. Add the `MiddlewareableBase` trait to the class that will use the middlewares\n\n```python\nclass App(MiddlewareableBase[Request]):\n    middlewares = [OneMiddleware] # add your middlewares here\n```\n\n### 4. Instantiate and use it\n\n```python\n# middlewareable\napp = App()\n\n# process request\nresult = await app.process_middlewares(Request(name=\"Hello\"))\n\n# check the result\nprint(request)\n\n# output:\n# OneMiddleware before\n# OneMiddleware after\n# Hello from OneMiddleware\n```\n\n## Traits\n\nYou can use the following traits to extend the functionality of your classes:\n\n- [AutoInstantiable](src/python_middlewareable/traits/auto_instantiable)\n- [DataStructurable](src/python_middlewareable/traits/data_structurable)\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n",
    "bugtrack_url": null,
    "license": "The MIT License (MIT)  Copyright (c) 2024 TheCodeCrate <loureiro.rg@gmail.com>  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "A simple library for working with middlewares in Python",
    "version": "1.0.0",
    "project_urls": {
        "documentation": "https://github.com/thecodecrate/python-middlewareable",
        "repository": "https://github.com/thecodecrate/python-middlewareable"
    },
    "split_keywords": [
        "middleware",
        " python",
        " library",
        " request-handling",
        " python-middleware"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "64acefc47208b02736aa74e5abe34f2e0d6dc834fa14a0fbc3ded42c710b9b14",
                "md5": "e4b96ed2637e987945992207552aa4c7",
                "sha256": "44e860b4acef6ba95064776b83cd97e09f5f426bd18de74b0ea64af9f1940fec"
            },
            "downloads": -1,
            "filename": "python_middlewareable-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e4b96ed2637e987945992207552aa4c7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 7945,
            "upload_time": "2024-09-17T17:35:07",
            "upload_time_iso_8601": "2024-09-17T17:35:07.740857Z",
            "url": "https://files.pythonhosted.org/packages/64/ac/efc47208b02736aa74e5abe34f2e0d6dc834fa14a0fbc3ded42c710b9b14/python_middlewareable-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bbc2f37d47f16c009ed5e702ec8dff2baa391758fe36a4e4ba9f917e3f57c050",
                "md5": "35086f71b6bb5a518fff857cd52daeb8",
                "sha256": "58709091fdb9c8f27624f2e09dc6317d9603b9c513710c30623ca74227260b4d"
            },
            "downloads": -1,
            "filename": "python_middlewareable-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "35086f71b6bb5a518fff857cd52daeb8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 7723,
            "upload_time": "2024-09-17T17:35:09",
            "upload_time_iso_8601": "2024-09-17T17:35:09.583936Z",
            "url": "https://files.pythonhosted.org/packages/bb/c2/f37d47f16c009ed5e702ec8dff2baa391758fe36a4e4ba9f917e3f57c050/python_middlewareable-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-17 17:35:09",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "thecodecrate",
    "github_project": "python-middlewareable",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "python-middlewareable"
}
        
Elapsed time: 0.38273s