Skip to main content

Middleware for every occasion

Project description

mediate

Middleware for every occasion

Installation

mediate can be installed from PyPI

pip install mediate

Usage

@middleware

from mediate import middleware

def 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}")
>>> hello("sam")
Hello, SAM!

Middleware

Middleware.bind

import mediate

middleware = 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}")
>>> hello("sam")
Hello, SAM!

Middleware.compose

import mediate

middleware = 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)
>>> hello("sam")
Hello, sam
>>> composed_hello("sam")
Hello, SAM!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mediate-0.1.8.tar.gz (3.5 kB view hashes)

Uploaded Source

Built Distribution

mediate-0.1.8-py3-none-any.whl (4.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page