Skip to main content

Like anyio task groups, but for contexts

Project description

anyio-contextgroup

anyio-contextgroup is a utiliity mechanism for establishing an anchored async context. This allows ExitStack-like behavior while maintaining structured concurrency. It works by running all context operations within a parent, outermost TaskGroup.

Getting started

Available as anyio-contextgroup on pypi.

At a glance

from collections.abc import AsyncGenerator
from contextlib import asynccontextmanager

from anyio_contextgroup import create_context_group


@asynccontextmanager
async def my_ctx(val: str) -> AsyncGenerator[int, None]:
    try:
        yield len(val)
    finally:
        print(f'{val=}')


async def main():
    async with create_context_group() as ctx_group:
        # Do some stuff
        ...

        for _ in range(5):
            ctx_retval = await ctx_group.enter_async_context(my_ctx, 'foo')
            assert ctx_retval == 3  # len('foo')

        # Do some other stuff
        ...

        # Now the context group will close, calling ``print()`` from ``my_ctx``

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

anyio_contextgroup-2026.4.14.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

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

anyio_contextgroup-2026.4.14.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file anyio_contextgroup-2026.4.14.0.tar.gz.

File metadata

  • Download URL: anyio_contextgroup-2026.4.14.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for anyio_contextgroup-2026.4.14.0.tar.gz
Algorithm Hash digest
SHA256 471c6acaae4e928ae4ffce1a92ccffba14f914d2abd285227557b8d17c786dc9
MD5 07c3d8fa688eb662ae083a7f1af3e816
BLAKE2b-256 063f5f02a0895078330d4bb54eb43d0c7ed248346179482c9d25fe14b67c27bc

See more details on using hashes here.

Provenance

The following attestation bundles were made for anyio_contextgroup-2026.4.14.0.tar.gz:

Publisher: on_release-publish_pypi.yaml on taev-tech/anyio_contextgroup

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

File details

Details for the file anyio_contextgroup-2026.4.14.0-py3-none-any.whl.

File metadata

File hashes

Hashes for anyio_contextgroup-2026.4.14.0-py3-none-any.whl
Algorithm Hash digest
SHA256 62bb86edc801277de1f4cf48dd9e10ee509ae551ebdc216e009921770164015e
MD5 761c51eb72c6f1150024250b47da5687
BLAKE2b-256 7ba36ad20c30b56b1d71902fea915f931443a4369c2207efa6f69520752bab9d

See more details on using hashes here.

Provenance

The following attestation bundles were made for anyio_contextgroup-2026.4.14.0-py3-none-any.whl:

Publisher: on_release-publish_pypi.yaml on taev-tech/anyio_contextgroup

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