A comprehensive decorator toolkit with 100 production-grade decorators.
Project description
Ibhax - The Ultimate Decorator Toolkit
ibhax is a powerful and versatile Python library that provides 100 production-grade decorators to enhance your development workflow. It includes decorators for logging, debugging, caching, performance monitoring, security, error handling, and much more.
Features
✅ 100+ Ready-to-Use Decorators
✅ Production-Grade Implementation
✅ Performance & Debugging Tools
✅ Error Handling & Security Enhancements
✅ Logging & Monitoring Support
✅ Simple and Flexible API
Installation
Install ibhax using pip:
pip install ibhax
Quickstart
Import DecoratorFactory and start using decorators right away:
from ibhax.decorators import DecoratorFactory
factory = DecoratorFactory()
@factory.deprecated("Use `new_function()` instead.")
def old_function():
print("This function is deprecated.")
old_function()
Example Output:
============================================================
DEPRECATION NOTICE
Function : old_function
Location : example.py:8
Reason : Use `new_function()` instead.
Recommendation : Please update your code accordingly.
============================================================
This function is deprecated.
Available Decorators (Highlights)
The DecoratorFactory class provides 100 powerful decorators. Here are a few:
| Decorator Name | Description |
|---|---|
@factory.deprecated |
Marks a function as deprecated with a custom warning. |
@factory.log_execution_time |
Logs the execution time of a function. |
@factory.retry |
Retries a function multiple times if it fails. |
@factory.suppress_errors |
Suppresses and logs exceptions instead of breaking the program. |
@factory.cache_results |
Caches function results to improve performance. |
@factory.debug |
Logs function calls and arguments for debugging. |
@factory.thread_safe |
Ensures a function is thread-safe. |
@factory.rate_limit |
Limits the rate at which a function can be called. |
@factory.trace |
Traces execution step-by-step for debugging. |
@factory.timeout |
Sets a time limit on function execution. |
Usage Examples
1. Logging Execution Time
@factory.log_execution_time
def slow_function():
import time
time.sleep(2)
print("Finished")
slow_function()
Output:
Execution time of slow_function: 2.0000 seconds
Finished
2. Retrying a Function on Failure
@factory.retry(attempts=3, delay=1)
def unstable_function():
import random
if random.random() < 0.7:
raise ValueError("Random failure!")
print("Success!")
unstable_function()
3. Suppressing Errors
@factory.suppress_errors(default="Error occurred!")
def risky_function():
raise ValueError("Oops!")
print(risky_function()) # Output: Error occurred!
4. Debugging Function Calls
@factory.debug
def add(a, b):
return a + b
add(2, 3)
Output:
DEBUG: add called with args: (2, 3), kwargs: {}
DEBUG: add returned 5
5. Rate Limiting Function Calls
@factory.rate_limit(calls=2, period=5)
def limited_function():
print("Executed")
limited_function()
limited_function()
limited_function() # This call may be blocked if made too soon.
6. Enforcing Thread Safety
@factory.thread_safe
def safe_function():
print("Thread-safe function running.")
7. Tracing Function Execution
@factory.trace
def traced_function():
x = 5
y = x * 2
return y
traced_function()
Listing All Decorators
To see all available decorators with descriptions:
factory.list_decorators()
Contributing
We welcome contributions! Feel free to:
- Report issues
- Request new decorators
- Submit pull requests
Clone the repository and install the package in development mode:
git clone https://github.com/ibhax/decorator_factory.git
cd decorator_factory
pip install -e .
License
ibhax is licensed under the MIT License.
Links
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 ibhax-1.0.0.tar.gz.
File metadata
- Download URL: ibhax-1.0.0.tar.gz
- Upload date:
- Size: 17.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
193c932115e3b80dce55f9033f849565302d4f12e7b7e5c7f7eec15955985f80
|
|
| MD5 |
c6994ab4204649e3b28f9ee5f141ea2c
|
|
| BLAKE2b-256 |
a225f6e5007e58e431b9460b9439db8f47c0c628cc99890797eacf99c65e3178
|
File details
Details for the file ibhax-1.0.0-py3-none-any.whl.
File metadata
- Download URL: ibhax-1.0.0-py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b69bcd20cfa174c976a74d9d655747ecb00322434b1c8a28beaf91b811d037db
|
|
| MD5 |
73e8234828c523e494a656cdba637788
|
|
| BLAKE2b-256 |
b3559c986727ce1a7e3c5f867d1e63177c1d87f2aa872e385f42df60a502290a
|