Common Python utilities including DAG task framework, caching, rate limiting, RW locks, and parameter helpers
Project description
shutilspy
Python utilities including DAG task framework, caching, rate limiting, RW locks, and parameter helpers.
Features
- DAG Framework - Build and execute directed acyclic graph workflows with sync/async tasks, routing, streaming, and service tasks
- Caching - TTL and LRU caches with persistent storage (lzma+pickle), auto-save by step/interval, and decorator support
- Rate Limiting - Token-bucket, QPS, and concurrency limiters with sync/async support and decorator
- RW Locks - Read-write locks for both sync (
RWLock) and async (AsyncRWLock) code - Smart Lock - Adaptive lock (
SmartLock,SmartRWLock) with automatic strategy selection based on operation duration - Parameter Helpers - Dataclass utilities for serialization (
asdict,asjson), deserialization (dict_to_dataclass), and hidden fields (Hide/HIDE) - Image Size - Get image dimensions from binary headers without full decoding (GIF, PNG, JPEG, TIFF, SVG, WebP)
Installation
pip
# without DAG visualizer
pip install shutilspy
# with DAG visualizer
pip install shutilspy[visualizer]
conda
# without DAG visualizer
conda install shlllshlll::shutilspy
# with DAG visualizer
conda install shlllshlll::shutilspy-visualizer
Optional dependencies
pip install shutilspy[visualizer] # Flask-based DAG visualization
Quick Examples
Singleton
from shutils import singleton
@singleton
class MyClass:
pass
assert MyClass() is MyClass()
Caching
from shutils import cached
@cached(backend="ttl", ttl=300)
def expensive(x):
return x * 2
DAG Pipeline
from shutils.dag import DAG, AsyncFunctionTask, Executor
dag = DAG()
async def step_a(ctx):
ctx.context.sync_white_board["a"] = "done"
return ctx
async def step_b(ctx):
val = ctx.context.sync_white_board.get("a")
ctx.context.sync_white_board["b"] = f"{val}_processed"
return ctx
dag.add_task(AsyncFunctionTask(step_a, name="A"))
dag.add_task(AsyncFunctionTask(step_b, name="B"), [task_a])
dag.build()
results = await Executor(dag).run()
Rate Limiting
from shutils import limiter
@limiter(calls=10, period=1)
def api_call():
return "response"
Documentation
Full documentation is available at the docs.
Development
pixi install
pixi run test # Run tests with coverage
pixi run lint # Run ruff linter
pixi run format # Run ruff formatter
pixi run docs-serve # Start docs server
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file shutilspy-0.1.1-py3-none-any.whl.
File metadata
- Download URL: shutilspy-0.1.1-py3-none-any.whl
- Upload date:
- Size: 65.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5f8bd881957d9e242a947959852a61a791bf40c54088065165cb5bbf76262f0
|
|
| MD5 |
3574616afec0fccf0020915ee688dd20
|
|
| BLAKE2b-256 |
55cc3bb9ac48df13e05d4cfd64b8a9ad671e2396e66ba4c28846ead95e929a05
|
Provenance
The following attestation bundles were made for shutilspy-0.1.1-py3-none-any.whl:
Publisher:
release.yml on shlllshlll/shutilspy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
shutilspy-0.1.1-py3-none-any.whl -
Subject digest:
c5f8bd881957d9e242a947959852a61a791bf40c54088065165cb5bbf76262f0 - Sigstore transparency entry: 1338418326
- Sigstore integration time:
-
Permalink:
shlllshlll/shutilspy@1fe742418ec47f02c83821718862775f710fa77b -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/shlllshlll
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@1fe742418ec47f02c83821718862775f710fa77b -
Trigger Event:
push
-
Statement type: