Skip to main content

contextmodel

Alternative interface to context variables for practical scenarios.

>>> from contextmodel import context_get, context_set
>>> from dataclasses import dataclass

>>> @dataclass
... class Foo:
...     x: int | None = None

>>> @context_set(Foo(x=1))
... def f() -> None:
...     print(context_get(Foo))
>>> f()
Foo(x=1)

>>> from contextmodel import ContextAPIGetter, ModelGetter
>>> from typing import ClassVar

>>> @dataclass
... class Foo:
...     context = ContextAPIGetter()
...     current = ModelGetter()
...     x: int | None = None

>>> with Foo.context.init(x=2):
...     print(Foo.context.get())
Foo(x=2)

>>> @Foo.context.init(x=3)
... def f() -> None:
...     print(context_get(Foo))
>>> f()
Foo(x=3)

>>> def oops() -> None:
...     print(Foo.current)
>>> oops()
Traceback (most recent call last):
  ...
LookupError: expected a context_set(Foo(...)) prior to this call

Works with type hints:

image

Metadata

Release files for contextmodel 0.3.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 contextmodel 0.3.1
File Size Uploaded Provenance Actions
contextmodel-0.3.1.tar.gz 43.6 kB With provenance Details for contextmodel-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for contextmodel 0.3.1
File Interpreter ABI Platform Actions
contextmodel-0.3.1-py3-none-any.whl Python 3 none any Details for contextmodel-0.3.1-py3-none-any.whl

Total release size: 47.4 kB

Release files / contextmodel-0.3.1.tar.gz

Download URL contextmodel-0.3.1.tar.gz
Size 43.6 kB
Tags Source
SHA-256 checksum
How to use checksums
1c9fd20c29bf476523faa466a53f4f21f13f82c25e1b4d8d60e95aab5ed7576e
BLAKE2b-256 checksum
How to use checksums
f8ead0b22f4ca8b6cd4aa858c89fa065e61bcdf98bd62bb853317de459b7b5af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 9, 2026.

Transparency log

Release files / contextmodel-0.3.1-py3-none-any.whl

Download URL contextmodel-0.3.1-py3-none-any.whl
Size 3.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a133bb96c251df84baf99897f4fc67d2f4e1522be1093d0636b74996d51e088c
BLAKE2b-256 checksum
How to use checksums
222cd4343798e655ec21c09c5a372a8311da7d3f5db55a60265d066ca87fb660
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 9, 2026.

Transparency log

Security for contextmodel 0.3.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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for contextmodel-0.3.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 9, 2026.

Transparency log

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.

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