Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tombulled/mediate
Middleware for every occasion
https://github.com/tombulled/mediate
Last synced: 23 days ago
JSON representation
Middleware for every occasion
- Host: GitHub
- URL: https://github.com/tombulled/mediate
- Owner: tombulled
- License: mit
- Created: 2021-11-07T18:29:53.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-05T19:40:08.000Z (almost 2 years ago)
- Last Synced: 2024-09-26T02:50:02.764Z (3 months ago)
- Language: Python
- Homepage: https://pypi.org/project/mediate/
- Size: 32.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mediate
Middleware for every occasion## Installation
`mediate` can be installed from [PyPI](https://pypi.org/project/mediate/)
```console
pip install mediate
```## Usage
### `@middleware`
```python
from mediate import middlewaredef shout(call_next, name):
return call_next(name.upper())def exclaim(call_next, name):
return call_next(name + "!")@middleware(shout, exclaim)
def hello(name):
print(f"Hello, {name}")
``````python
>>> hello("sam")
Hello, SAM!
```### `Middleware`
#### `Middleware.bind`
```python
import mediatemiddleware = mediate.Middleware()
@middleware
def shout(call_next, name):
return call_next(name.upper())@middleware
def exclaim(call_next, name):
return call_next(name + "!")@middleware.bind
def hello(name):
print(f"Hello, {name}")
``````python
>>> hello("sam")
Hello, SAM!
```#### `Middleware.compose`
```python
import mediatemiddleware = mediate.Middleware()
@middleware
def shout(call_next, name):
return call_next(name.upper())@middleware
def exclaim(call_next, name):
return call_next(name + "!")def hello(name):
print(f"Hello, {name}")composed_hello = middleware.compose(hello)
``````python
>>> hello("sam")
Hello, sam
>>> composed_hello("sam")
Hello, SAM!
```