Principle:Eventual Inc Daft Session Management
| Knowledge Sources | |
|---|---|
| Domains | Data_Engineering, Session_Management |
| Last Updated | 2026-02-08 00:00 GMT |
Overview
Technique for managing connection state, catalogs, and execution context in Daft.
Description
A Session holds state for catalog connections, namespace resolution, provider configuration, and SQL execution. It acts as the central orchestrator for all data access and query operations. Sessions can be used as context managers for scoped state, or as standalone objects for explicit state management. A global default session is automatically created from the environment when needed.
Usage
Use session management when you need to manage multiple catalogs, configure AI providers, register temporary tables, or execute SQL queries with catalog awareness.
Theoretical Basis
Session-scoped state management using context variables for thread-safe concurrent access. The session hierarchy follows:
1. Context-manager session (innermost scope, via `with daft.session() as sess:`)
2. Global active session (set via set_session or auto-created)
3. Environment-based session (created from DAFT_SESSION config)
State resolution:
session -> current_catalog -> current_namespace -> table resolution
session -> current_provider -> current_model -> AI operations
Context variables (contextvars.ContextVar) ensure that concurrent threads or async tasks each see their own session state without interference.