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.
Metadata
Release files for python-middlewareable 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| python_middlewareable-1.0.0.tar.gz | 7.7 kB | Without provenance | Details for python_middlewareable-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| python_middlewareable-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for python_middlewareable-1.0.0-py3-none-any.whl |
Total release size: 15.7 kB
Release files / python_middlewareable-1.0.0.tar.gz
| Download URL | python_middlewareable-1.0.0.tar.gz |
|---|---|
| Size | 7.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
58709091fdb9c8f27624f2e09dc6317d9603b9c513710c30623ca74227260b4d
|
|
BLAKE2b-256 checksum How to use checksums |
bbc2f37d47f16c009ed5e702ec8dff2baa391758fe36a4e4ba9f917e3f57c050
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.9
|
Release files / python_middlewareable-1.0.0-py3-none-any.whl
| Download URL | python_middlewareable-1.0.0-py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
44e860b4acef6ba95064776b83cd97e09f5f426bd18de74b0ea64af9f1940fec
|
|
BLAKE2b-256 checksum How to use checksums |
64acefc47208b02736aa74e5abe34f2e0d6dc834fa14a0fbc3ded42c710b9b14
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.9
|
Security for python-middlewareable 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.