A collection of production-ready Python decorators and generators
Project description
Python Decorators & Generators
A curated collection of production-ready, reusable Python decorators and generators — crafted using modern Python best practices.
This package includes:
- ✅ Common decorators like logging, retrying, caching, timing, and more
- ✅ Generators for streaming data, infinite sequences, and efficient file processing
- ✅ Unit tests and GitHub Actions CI
- ✅ Editable install via
pyproject.tomlfor clean imports
📦 Installation (Editable Mode)
Make sure you have Python 3.8+ and pip:
git clone https://github.com/your-username/python-decorators-generators.git
cd python-decorators-generators
pip install -e .
✅ Decorators Included Decorator Description log_execution Logs function calls, arguments, return values, execution time, and exceptions retry_on_exception Retries a function on failure, with configurable retry count and delay cache_result In-memory caching with TTL support time_execution Logs how long a function takes to run
📂 Project Structure
python-decorators-generators/
├── decorators/
│ ├── logging_decorator.py
│ ├── retry_decorator.py
│ ├── cache_decorator.py
│ ├── time_decorator.py
│ ├── once.py
│ ├── memoize.py
│ ├── benchmark.py
│ ├── deprecated.py
│ └── async_safe.py
│
├── generators/
│ ├── fibonacci.py
│ ├── file_chunker.py
│ ├── tail_reader.py
│ ├── sliding_window.py
│ ├── paginated_api_reader.py
│ ├── batched_iterable.py
│ └── directory_watcher.py
│ └── csv_row_reader.py
│
├── examples/
│ └── demo_<name>.py
│
├── tests/
│ └── test_<name>.py
│
├── pyproject.toml
├── requirements.txt
└── README.md
✅ Decorators Included
| Decorator | Module | Description |
|---|---|---|
log_execution |
decorators.logging_decorator |
Logs function calls, arguments, return values, execution time, and errors |
retry_on_exception |
decorators.retry_decorator |
Retries a function on failure, with customizable retry count and delay |
cache_result |
decorators.cache_decorator |
In-memory caching with configurable TTL |
time_execution |
decorators.time_decorator |
Logs how long a function takes to run |
once |
decorators.once |
Ensures a function runs only once |
memoize |
decorators.memoize |
Simple non-TTL in-memory caching |
benchmark |
decorators.benchmark |
Logs function execution time, warns if it exceeds a threshold |
deprecated |
decorators.deprecated |
Emits a warning when a deprecated function is called |
suppress_exceptions |
decorators.suppress_exceptions |
Suppresses specified exceptions and optionally logs them |
rate_limiter |
decorators.rate_limiter |
Limits how frequently a function can be called |
validate_types |
decorators.validate_types |
Runtime type checking for arguments and return values |
async_safe |
decorators.async_safe |
Makes sync functions awaitable in async contexts |
🔁 Generators Included
| Generator | Module | Description |
|---|---|---|
fibonacci() |
generators.fibonacci |
Infinite lazy sequence of Fibonacci numbers |
file_chunker() |
generators.file_chunker |
Reads large files in fixed-size chunks using lazy loading |
tail_reader() |
generators.tail_reader |
Mimics tail -f to stream new lines from a file in real-time |
sliding_window() |
generators.sliding_window |
Yields a sliding window over an iterable |
paginated_api_reader() |
generators.paginated_api_reader |
Yields results from paginated API endpoints |
batched_iterable() |
generators.batched_iterable |
Yields fixed-size batches from any iterable |
directory_watcher() |
generators.directory_watcher |
Yields filenames as new files appear in a directory |
csv_row_reader() |
generators.csv_row_reader Streams |
rows from large CSVs as dictionaries |
🧪 Run Tests
Install dependencies:
pip install -r requirements.txt
Then run:
pytest tests/
🚀 CI/CD with GitHub Actions
This project includes a CI pipeline that runs on every push and PR to main, defined in .github/workflows/python-tests.yml. 🧠 Why This Repo?
This repository is ideal for:
-
Engineers who want reusable decorator utilities
-
Data engineers working with large files or streams
-
Anyone who wants to understand Python’s advanced features through real code
📬 Contributions
Feel free to fork this project, add more utilities (e.g., memoization, rate-limiting), or improve tests and documentation.
Let me know if you'd like a corresponding pyproject.toml now, or a downloadable .zip with the full folder setup.
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.0.tar.gz.
File metadata
- Download URL: pydecorx-1.0.0.tar.gz
- Upload date:
- Size: 12.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9be581acb75bb25e26f8944e18bead7d9514b56ff5837e7495cfc2b67d6870c
|
|
| MD5 |
2d1d052e7bca404fb20ae515b44a5405
|
|
| BLAKE2b-256 |
4c99fbdc7fd27afd93d6678ad861b78777a4209b6872117a9c3d6696d96074de
|
File details
Details for the file pydecorx-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pydecorx-1.0.0-py3-none-any.whl
- Upload date:
- Size: 13.1 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 |
87498d660c99112e6211f56ba85d4daf65dee2d1114b0efe376e059c0e29abbb
|
|
| MD5 |
2d605eeddbab55b5b793561c2e996f40
|
|
| BLAKE2b-256 |
6ab46031eace88ac4bed17d3c19cb8be33f0be0fbd119f6bf3a1a3ca3a1c6c59
|