Skip to content

Sessions

session

Managed execution contexts for eager tasks.

The session context manager sets up backend, cache, plugin, and event infrastructure so that eager tasks automatically participate in caching, hook dispatch, and event reporting. Workflows use session internally; notebooks and scripts can use it directly.

Three tiers of usage::

# 1. Bare call — no context, inline defaults, no reporters
result = add(x=1, y=2)

# 2. session — managed context for notebooks / scripts
with session(backend="thread", cache_store=".cache"):
    a = add(x=1, y=2)


# 3. @workflow — named, CLI-discoverable entry point
@workflow
def my_pipeline(x: int):
    return add(x=x, y=1)


my_pipeline.run(x=5)

session

session(
    *,
    backend: str | None = None,
    cache_store: str | CacheStore | None = None,
    dataset_store: str | DatasetStore | None = None,
    plugins: SerializablePlugin | list[SerializablePlugin] | None = None,
    settings: DagliteSettings | None = None,
) -> Iterator[SessionContext]

Synchronous context manager that sets up an execution context.

Parameters:

Name Type Description Default
backend str | None

Name of the backend to default. If None uses settings.backend.

None
cache_store str | CacheStore | None

Cache store configuration. Can be a CacheStore or a string path.

None
dataset_store str | DatasetStore | None

Dataset store configuration. Can be a DatasetStore or a string path.

None
plugins SerializablePlugin | list[SerializablePlugin] | None

Extra plugin instances for this session only.

None
settings DagliteSettings | None

A DagliteSettings override. Falls back to the global settings singleton.

None

Yields:

Type Description
SessionContext

The active SessionContext for the duration of the block.

Source code in src/daglite/session.py
@contextmanager
def session(
    *,
    backend: str | None = None,
    cache_store: str | CacheStore | None = None,
    dataset_store: str | DatasetStore | None = None,
    plugins: SerializablePlugin | list[SerializablePlugin] | None = None,
    settings: DagliteSettings | None = None,
) -> Iterator[SessionContext]:
    """
    Synchronous context manager that sets up an execution context.

    Args:
        backend: Name of the backend to default. If `None` uses `settings.backend`.
        cache_store: Cache store configuration. Can be a `CacheStore` or a string path.
        dataset_store: Dataset store configuration. Can be a `DatasetStore` or a string path.
        plugins: Extra plugin instances for this session only.
        settings: A `DagliteSettings` override. Falls back to the global settings singleton.

    Yields:
        The active `SessionContext` for the duration of the block.
    """
    plugins = plugins if isinstance(plugins, list) else [plugins] if plugins is not None else []
    ctx = _build_context(
        backend=backend,
        cache_store=cache_store,
        dataset_store=dataset_store,
        plugins=plugins,
        settings=settings,
    )
    with ctx:
        with _processors_context(ctx):
            yield ctx

async_session async

async_session(
    *,
    backend: str | None = None,
    cache_store: str | CacheStore | None = None,
    dataset_store: str | DatasetStore | None = None,
    plugins: SerializablePlugin | list[SerializablePlugin] | None = None,
    settings: DagliteSettings | None = None,
) -> AsyncIterator[SessionContext]

Async context manager that sets up an eager execution context.

Parameters:

Name Type Description Default
backend str | None

Name of the backend to default. If None uses settings.backend.

None
cache_store str | CacheStore | None

Cache store configuration. Can be a CacheStore or a string path.

None
dataset_store str | DatasetStore | None

Dataset store configuration. Can be a DatasetStore or a string path.

None
plugins SerializablePlugin | list[SerializablePlugin] | None

Extra plugin instances for this session only.

None
settings DagliteSettings | None

A DagliteSettings override. Falls back to the global settings singleton.

None

Yields:

Type Description
AsyncIterator[SessionContext]

The active SessionContext for the duration of the block.

Source code in src/daglite/session.py
@asynccontextmanager
async def async_session(
    *,
    backend: str | None = None,
    cache_store: str | CacheStore | None = None,
    dataset_store: str | DatasetStore | None = None,
    plugins: SerializablePlugin | list[SerializablePlugin] | None = None,
    settings: DagliteSettings | None = None,
) -> AsyncIterator[SessionContext]:
    """
    Async context manager that sets up an eager execution context.

    Args:
        backend: Name of the backend to default. If `None` uses `settings.backend`.
        cache_store: Cache store configuration. Can be a `CacheStore` or a string path.
        dataset_store: Dataset store configuration. Can be a `DatasetStore` or a string path.
        plugins: Extra plugin instances for this session only.
        settings: A `DagliteSettings` override. Falls back to the global settings singleton.

    Yields:
        The active `SessionContext` for the duration of the block.
    """
    plugins = plugins if isinstance(plugins, list) else [plugins] if plugins is not None else []
    ctx = _build_context(
        backend=backend,
        cache_store=cache_store,
        dataset_store=dataset_store,
        plugins=plugins,
        settings=settings,
    )
    with ctx:
        with _processors_context(ctx):
            yield ctx