Skip to main content
Flask-Context
=============

Supply an arbitrary context object to Flask and use it in your application.

After many years of writing apps, we (Real Kinetic) decided that one of the
most pragmatic things you can do for the long term stabilty and maintainability
of your app is to use and pass round a context object that has access to all
the business level state that you need. This should be passed around everywhere
so when debugging you can figure out what request the problem occurred in.

One of the simplest examples is that of a correlation id. Let's imagine a
microservice environment with a single request that comes in from the outside
is potentially handled by one or more services. When you start distributing
requests like that it becomes really hard to debug errors when they occur. It
would be extremely useful if a unique token was used to tie all of the
processing done by the various services together so that any logging aggregation
could make it easy to get a better picture of what happened. This is where
projects like openzipkin come in.

Other examples may include passing round a ``user_id`` for the request.

This library extracts the Flask specifics so the engineer can focus on the
business problem.

Usage
-----

```python
import uuid
from flask import Flask
from flask_context import FlaskContext, current_context


class MyContext(object):
def __init__(self, correlation_id=None):
self.correlation_id = correlation_id or uuid.uuid4().hex


app = Flask(__name__)

flask_ctx = FlaskContext(MyContext, app)


@app.route('/')
def index():
return current_context.correlation_id


if __name__ == '__main__':
app.run('127.0.0.1', 5000)
```

Head on over to ``http://127.0.0.1:5000/'`` and you should see a unique id
everytime you refresh the page.

Development
-----------

Setting up:

```bash
$ mkvirtualenv flask-context
(flask-context) $ pip install -r requirements_dev.txt
```

Running the tests:

```bash
(flask-context) $ nosetests --with-coverage
```

Metadata

Release files for Flask-Context 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Flask-Context 0.1
File Size Uploaded Provenance
Flask-Context-0.1.tar.gz 4.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for Flask-Context 0.1
File Interpreter ABI Platform
Flask_Context-0.1-py2-none-any.whl Python 2 none any Details

Total release size: 10.8 kB

Release files / Flask-Context-0.1.tar.gz

Download URL Flask-Context-0.1.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
6fa3e63d4cc301a77bd28d091350086aec94db40523c756ca2c812f49679d731
BLAKE2b-256 checksum
How to use checksums
a2eb312e595da93bea0bc8f0c609cd5c4bbd550876319db61cc4c7c4209202f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / Flask_Context-0.1-py2-none-any.whl

Download URL Flask_Context-0.1-py2-none-any.whl
Size 6.8 kB
Tags Python 2
SHA-256 checksum
How to use checksums
7233563f516a070cddeda780c3c69535daca2adef1991cfec33dd1c926c9b5fa
BLAKE2b-256 checksum
How to use checksums
1dcc89e3662a04b7ef742646db210556130f8412de9804a83cfc30ebb234ebf6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for Flask-Context 0.1

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.

Release history Release notifications | RSS feed

This release

0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page