Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Onion Model in Python

Project description


Onion Model in Python. Pyton 洋葱模型

pip install compose4py



Import compose4py:

from compose4py import Compose

All the usual function composition you know and love:

    def mw_1(ctx, loader_context):
        print("mw_1: %s" % ctx)
        print("mw_1 loader_context: %s" % loader_context)
        ctx += ":mw1"
        ctx = yield ctx
        ctx += ":post_mw1"
        return ctx

    def mw_2(ctx):
        print("mw_2: %s" % ctx)
        ctx += ":mw2"
        ctx = yield ctx
        ctx += ":post_mw2"
        return ctx

    def mw_3(ctx):
        print("mw_3: %s" % ctx)
        ctx += ":mw3"
        return ctx

    compose = Compose(mw_1, mw_2, mw_3, loader_context = {"foo": "bar"})
    result = compose("foo")
    print("final: %s" % result)
    # final: foo:mw1:mw2:mw3:post_mw2:post_mw1

Give credits to



Copyright (2018-2020) 北京华夏春松科技有限公司

Apache License Version 2.0

chatoper banner

Project details

Download files

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

Files for compose4py, version 1.2.0
Filename, size File type Python version Upload date Hashes
Filename, size compose4py-1.2.0-py3-none-any.whl (7.1 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size compose4py-1.2.0.tar.gz (5.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page