Skip to main content

A nice interface to context variables

Project description

contextmodel

Alternative interface to context variables for practical scenarios.

>>> from contextmodel import ContextModel, context_create, context_get
>>> from dataclasses import dataclass

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

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

>>> with Foo.model_context.create(x=2):
...     print(Foo.model_current.x)
2

>>> @Foo.model_context.create(x=3)
... def f() -> None:
...     print(Foo.model_current.x)
>>> f()
3

Works with type hints:

image

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

contextmodel-0.1.0.tar.gz (43.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

contextmodel-0.1.0-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file contextmodel-0.1.0.tar.gz.

File metadata

  • Download URL: contextmodel-0.1.0.tar.gz
  • Upload date:
  • Size: 43.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for contextmodel-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c84156d973b9ce50af165e966bfaeaab7b770abbc4c721d5f4dafe0650f0e9fd
MD5 0c476941570a1a5cc55dbd573a1e9acb
BLAKE2b-256 4fddb8b31c73bbbb5ec70efbf5f56a4ddf7a18d1a2b2750f59277cdc10020e3a

See more details on using hashes here.

Provenance

The following attestation bundles were made for contextmodel-0.1.0.tar.gz:

Publisher: ci.yml on johnslavik/contextmodel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file contextmodel-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: contextmodel-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for contextmodel-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 035d93d2bf34cc5d6cec57da23809ef86875fd7067a97a0e187098a76229fe9c
MD5 cf177b8a73ce9d21e3ce455cbf5fa9dc
BLAKE2b-256 8b5c425747824b03fcae4c8b10d515d4653563ca6bdb047e78c507778bd8014c

See more details on using hashes here.

Provenance

The following attestation bundles were made for contextmodel-0.1.0-py3-none-any.whl:

Publisher: ci.yml on johnslavik/contextmodel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page