A collection of production-ready Python decorators and generators
Project description
pydecorx
A collection of production-ready Python decorators and generators
pydecorx provides a set of modular, reusable utilities to simplify common Python patterns like logging, retrying, caching, type validation, and file/data stream processing.
📦 Features
✅ Decorators
log_execution– Log function calls, arguments, return values, and execution timeretry_on_exception– Retry failed function calls with configurable delaycache_result– In-memory caching with TTL supporttime_execution– Log how long a function takes to runonce– Ensure a function runs only oncememoize– Simple caching without TTLbenchmark– Warn if a function exceeds an execution thresholddeprecated– Emit deprecation warningssuppress_exceptions– Gracefully handle and suppress specified exceptionsrate_limiter– Limit how often a function can be calledvalidate_types– Enforce type hints at runtimeasync_safe– Make sync functions awaitable in async code
🔁 Generators
fibonacci– Infinite Fibonacci number streamfile_chunker– Read large files in fixed-size chunkstail_reader– Mimicstail -ffor real-time file streamingsliding_window– Yields fixed-size windows over iterablespaginated_api_reader– Read items from paginated APIsbatched_iterable– Yield batches of items from iterablesdirectory_watcher– Yield new filenames as they appear in a directorycsv_row_reader– Stream rows from large CSV files
🔧 Installation
pip install pydecorx
Or from source (editable):
git clone https://github.com/manas-shinde/python-decorators-generators.git
cd python-decorators-generators
pip install -e .
🚀 Usage Example
from decorators.retry_decorator import retry_on_exception
@retry_on_exception(retries=3, delay=1)
def fetch_data():
# some flaky operation
pass
from generators.batched_iterable import batched_iterable
for batch in batched_iterable(range(10), batch_size=3):
print(batch)
🧪 Testing
Install test dependencies and run tests:
pip install -r requirements.txt
pytest tests/
📚 License
MIT License
🔗 Project Links
Source: GitHub Repository
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 Distribution
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 pydecorx-1.0.1.tar.gz.
File metadata
- Download URL: pydecorx-1.0.1.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cde1344ab07edd9ced65a2d730d0b64225be333c7e1e3664392879995e2339d9
|
|
| MD5 |
3b4b55564199bb77cfae9752ede0c825
|
|
| BLAKE2b-256 |
3a2df0785e8cd1f303dde54d6c0b0fabe7db28555d234afa3eb84b482b1ee8e5
|
File details
Details for the file pydecorx-1.0.1-py3-none-any.whl.
File metadata
- Download URL: pydecorx-1.0.1-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
954a4bfc0b8773866d80c2c45dc2a001dd1c9b092233b51f650ffbf462b858c0
|
|
| MD5 |
4fe3c53399d4695fff69fa1db835ebbb
|
|
| BLAKE2b-256 |
6f2bf61af4c524167ed5b84d4bb4c13a344650880092c0f2403f877bee5750f2
|