Metadata-Version: 2.1
Name: anyio_contextgroup
Version: 2026.4.14.0
Summary: Like anyio task groups, but for contexts
Requires-Python: >=3.12
Requires-Dist: anyio>=4.13.0
Description-Content-Type: text/markdown

# 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

```python
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``
```
