Skip to main content

A easy way to manage resource within request context

Project description

Request Context Manager

Purpose of Request Context

When application begins handling request, request context manager create a request context. Within request context, you could access the attributes bound with the context. If you try to access attributes outside the context, OutsideContext exception will be raised.

How to Create Request Context Manager

from request_context_manager import RequestContextManager
from request_context_manager import RequestContextAttr

# create request context manager
your_request_context_manager = RequestContextManager('your_request_context_manager_name')

# bind request context attribute
class YourRequestContextAttr:
    _request_context_manager = your_request_context_manager

    your_attr = RequestContextAttr('your_attr_name', _request_context_manager)

# get/set request context attribute within request context
with your_request_context_manager.under_request_context():
    YourRequestContextAttr.your_attr.set("hello world")
    your_attr_value = YourRequestContextAttr.your_attr.get() # "hello world"

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

request_context_manager-0.0.3.tar.gz (5.7 kB view hashes)

Uploaded Source

Built Distribution

request_context_manager-0.0.3-py3-none-any.whl (3.5 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