Skip to main content

Xinyu's common utilities

Project description

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)

Project details


Download files

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

Source Distribution

yutilx-0.0.3.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

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

yutilx-0.0.3-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file yutilx-0.0.3.tar.gz.

File metadata

  • Download URL: yutilx-0.0.3.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for yutilx-0.0.3.tar.gz
Algorithm Hash digest
SHA256 42a1f3cabfe9d80127bb815b06c156793e725b4150393ff7fd8f21e5feb4ad3c
MD5 d6e6ee9bd1c548b9dc9ed1d52924afc8
BLAKE2b-256 43d60873b9465196b4695613cf4f5e7d536fd4a3b287b6230d2fdb2a43ac4698

See more details on using hashes here.

File details

Details for the file yutilx-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: yutilx-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for yutilx-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4fb5aeecef44a581e8d1304bed1fc094719faef8a8828c4ade07a3dec4fc493a
MD5 081df2d261a43867998ab9dacec6c1ce
BLAKE2b-256 0f147b28b788d04fdbc03d6f39b60fac8360b38c2ea3229c8787c4d416933232

See more details on using hashes here.

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