Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

shutilspy-0.1.1-py3-none-any.whl (65.9 kB view details)

Uploaded Python 3

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

Hashes for shutilspy-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c5f8bd881957d9e242a947959852a61a791bf40c54088065165cb5bbf76262f0
MD5 3574616afec0fccf0020915ee688dd20
BLAKE2b-256 55cc3bb9ac48df13e05d4cfd64b8a9ad671e2396e66ba4c28846ead95e929a05

See more details on using hashes here.

Provenance

The following attestation bundles were made for shutilspy-0.1.1-py3-none-any.whl:

Publisher: release.yml on shlllshlll/shutilspy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page