Skip to main content

Python Context Information

PyPI PyPI - Python Version GitHub last commit GitHub stars

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

Contribution guidelines for this project

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)

Source distribution for kontext 1.3.0
File Size Uploaded
kontext-1.3.0.tar.gz 4.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kontext 1.3.0
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

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