Registry / devops / xlocal

xlocal

JSON →
library0.5pypypi✓ verified 81d ago

xlocal is a library for execution-local storage, providing a cleaner alternative to thread-local (and global) mutable state. It supports both thread-based and asynchronous (asyncio) contexts, and its variables are scope-safe and automatically cleaned up. Current version is 0.5; the library is in maintenance mode with rare releases.

pip install xlocal
INSTALL
IMPORT
SIG · XLOCAL
X
xlocal
devopspythonv0.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

xlocal
from xlocal import xlocal
from xlocal import ExecutionLocal
WithXLocals
from xlocal import WithXLocals

Create an execution-local variable with a default factory.

from xlocal import ExecutionLocal local_var = ExecutionLocal(default=lambda: []) def add_item(item): local_var.value.append(item) return local_var.value # In the same execution context: print(add_item('a')) # ['a'] print(add_item('b')) # ['a', 'b'] # In a different thread or asyncio task, it has its own list. # The default is called once per execution context when first accessed.
Debug
Known issues
gotchaThe `default` callable is called every time `value` is first accessed in a new execution context. If the factory is expensive or has side effects (e.g., opening a file), use a singleton pattern or lazy initialization inside the factory.
fix
Wrap expensive initialization in a `lru_cache` or similar to avoid repeated calls.
affects: <=0.5
gotcha`ExecutionLocal` does not support synchronization between contexts. If you need to share data across threads/tasks, use a different mechanism like `threading.local` with locks or `asyncio.Queue`.
fix
Use xlocal only for context-local data, not for cross-context communication.
affects: <=0.5
deprecatedThe `xlocal` module provides a legacy API `xlocal.Proxy` which is deprecated in favor of `ExecutionLocal`.
fix
Replace `from xlocal import Proxy` with `from xlocal import ExecutionLocal`.
affects: <=0.5
Upgrade
Version history
0.5latest on PyPI · released Nov 16, 2012
Audit
Dependencies

No dependency data recorded yet.

Agent activity
37 hits · last 30 days
node
36
Resources
xlocal — pip install xlocal · libregistry