Python Context Information
The plugin allows to transfer a context between functions. Inspired by context-logging.
You can use it for logging data which does not change and can be correlated, e.g. trace_id, correlation_id etc.
Features
- Thread-safe context management
- Customizable log records
- Easy-to-use API
Installation
pip install kontext
Usage
import logging
from kontext import Context, current_context, setup_log_record
logging.basicConfig(format="%(message)s %(kontext)s", level=logging.INFO)
logger = logging.getLogger(__name__)
def bar():
current_context["foo"] = "bar"
logger.info("bar")
@Context()
def foo():
current_context["key"] = "value"
logger.info("foo")
bar()
setup_log_record()
foo()
logger.info("Finish")
# foo {'key': 'value'}
# bar {'key': 'value', 'foo': 'bar'}
# Finish {}
For more examples, please refer to the examples directory.
License
Contribution
Metadata
Release files for kontext 1.3.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 | |
|---|---|---|---|
| kontext-1.3.0.tar.gz | 4.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| kontext-1.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.3 kB
Release files / kontext-1.3.0.tar.gz
| Download URL | kontext-1.3.0.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8241e030664364dcfcde0093c7d6b7bab6355c602031221eec51fe1666fd57dd
|
|
BLAKE2b-256 checksum How to use checksums |
ca70116580c2d3116e681dcdae6a7c49f6283e9f90c18cae7d5d391c9a9b83f7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.11.9 Linux/6.5.0-1022-azure
|
Release files / kontext-1.3.0-py3-none-any.whl
| Download URL | kontext-1.3.0-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3cbea687d230000153bb64a1f11663337a2e529a3b87bdc03443a59ce162060d
|
|
BLAKE2b-256 checksum How to use checksums |
526c8171ad722a324e11b0b0ea89349577f238d1ce560cf3de689f2dd3628276
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.11.9 Linux/6.5.0-1022-azure
|