Skip to main content

yutilx

PyPI version Python Version License: MIT

A Python utilities library providing efficient parallel processing with caching capabilities.

Features

  • Parallel Processing: Execute functions concurrently using ThreadPoolExecutor
  • Smart Caching: Automatic result caching with MD5-based deduplication
  • Flexible Storage: Choose between file-based (JSONL) or in-memory caching
  • Retry Logic: Built-in retry mechanism for handling transient failures
  • Progress Tracking: Real-time progress visualization with tqdm
  • Thread-Safe: Safe concurrent access to cache

Installation

pip install yutilx

Quick Start

from yutilx import CachedParallelProcessor

# Define your processing function
def process_text(text: str) -> str:
    # Your processing logic here
    return text.upper()

# Create a processor instance
processor = CachedParallelProcessor(
    process_func=process_text,
    max_retry_cnt=3,
    cache_filename="results.jsonl"
)

# Process data in parallel
inputs = ["hello", "world", "python", "rocks"]
processor.run(inputs, num_threads=4)

# Retrieve results
results = processor.get_result(inputs)
print(results)  # ['HELLO', 'WORLD', 'PYTHON', 'ROCKS']

API Reference

CachedParallelProcessor

CachedParallelProcessor(
    process_func: Callable[[str], str],
    max_retry_cnt: int = 3,
    cache_filename: Optional[str] = None,
    cache_file_free: bool = False
)

Parameters

  • process_func: Function to process each input string
  • max_retry_cnt: Maximum retry attempts for failed processing (default: 3)
  • cache_filename: Path to cache file (default: "cache.jsonl")
  • cache_file_free: If True, use in-memory cache only (default: False)

Methods

  • run(input_lis: list[str], num_threads: int = 10): Process inputs in parallel
  • get_result(input_lis: list[str]) -> list[str]: Retrieve cached results

Development

This project uses uv for dependency management.

Setup Development Environment

# Clone the repository
git clone https://github.com/cauyxy/yutilx.git
cd yutilx

# Install dependencies
uv sync

# Run tests
uv run pytest

# Format code
uv run ruff format

# Lint code
uv run ruff check

Building

# Build distribution packages
uv build

License

MIT License - see LICENSE for details.

Author

Xinyu Yang (cauyxy@gmail.com)

Release files for yutilx 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yutilx 0.0.3
File Size Uploaded
yutilx-0.0.3.tar.gz 22.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for yutilx 0.0.3
File Interpreter ABI Platform
yutilx-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 28.3 kB

Release files / yutilx-0.0.3.tar.gz

Download URL yutilx-0.0.3.tar.gz
Size 22.3 kB
Tags Source
SHA-256 checksum
How to use checksums
42a1f3cabfe9d80127bb815b06c156793e725b4150393ff7fd8f21e5feb4ad3c
BLAKE2b-256 checksum
How to use checksums
43d60873b9465196b4695613cf4f5e7d536fd4a3b287b6230d2fdb2a43ac4698
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / yutilx-0.0.3-py3-none-any.whl

Download URL yutilx-0.0.3-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4fb5aeecef44a581e8d1304bed1fc094719faef8a8828c4ade07a3dec4fc493a
BLAKE2b-256 checksum
How to use checksums
0f147b28b788d04fdbc03d6f39b60fac8360b38c2ea3229c8787c4d416933232
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page