react_context
An API to pass data down in the sub-function inspired by React Context
pip install react-context
Inspired by this reddit, here a React Context-like API for Python to pass data down in thesub-function without polluting all the function parameters.
Under the hood it uses inspect.stack().frame to register the element in the context manager. Frames may be available only in CPython.
Define context values
To define a context value use create_context(**kargws) function
with use_context(something=123):
...
Retrieve the value somewhere in the code inside of the context
To retrieve the value, use get_context(key) function
Complete example
def nested_function():
return get_context('something', 'default_value')
with use_context(something=123):
value = nested_function()
print(value) # 123
print(nested_function()) # 'default_value'
How to debug the context
To print in the console where a context has been defined in the stacktrace, replace get_context with debug_context(key, logger=print)
For the complete implementation and behaviour, please check the test file.
Metadata
Release files for react-context 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| react_context-1.0.0.tar.gz | 3.0 kB | Without provenance | Details for react_context-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| react_context-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for react_context-1.0.0-py3-none-any.whl |
Total release size: 6.3 kB
Release files / react_context-1.0.0.tar.gz
| Download URL | react_context-1.0.0.tar.gz |
|---|---|
| Size | 3.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e101e74b19277cecef17490945bf3b0bf3ad39f8ea23b090120096ce40add2e5
|
|
BLAKE2b-256 checksum How to use checksums |
737602e219c6d84fdad7a07ade72677940d90c58a4ba7a88268210b23c727c4f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.8
|
Release files / react_context-1.0.0-py3-none-any.whl
| Download URL | react_context-1.0.0-py3-none-any.whl |
|---|---|
| Size | 3.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
42af70da8c8e5c5d66018717dbf703330ae9a84d823b37f39fb01b49e2fa7411
|
|
BLAKE2b-256 checksum How to use checksums |
1e5dc506f070a7f9d5cb0d06abd8ca8683aad9e25c3b7ca8d621b1cc0060157e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.8
|
Security for react-context 1.0.0
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.