A simple library for working with middlewares in Python
Project description
Python-Middlewareable
A simple library for working with middlewares in Python.
Installation
pip install python-middlewareable
Usage
1. Define the payload structure
@dataclass
class Request(RequestBase): # inherit from RequestBase
name: str
2. Create a middleware
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
class App(MiddlewareableBase[Request]):
middlewares = [OneMiddleware] # add your middlewares here
4. Instantiate and use it
# 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:
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_middlewareable-1.0.0.tar.gz.
File metadata
- Download URL: python_middlewareable-1.0.0.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58709091fdb9c8f27624f2e09dc6317d9603b9c513710c30623ca74227260b4d
|
|
| MD5 |
35086f71b6bb5a518fff857cd52daeb8
|
|
| BLAKE2b-256 |
bbc2f37d47f16c009ed5e702ec8dff2baa391758fe36a4e4ba9f917e3f57c050
|
File details
Details for the file python_middlewareable-1.0.0-py3-none-any.whl.
File metadata
- Download URL: python_middlewareable-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44e860b4acef6ba95064776b83cd97e09f5f426bd18de74b0ea64af9f1940fec
|
|
| MD5 |
e4b96ed2637e987945992207552aa4c7
|
|
| BLAKE2b-256 |
64acefc47208b02736aa74e5abe34f2e0d6dc834fa14a0fbc3ded42c710b9b14
|