PythonWrap
A comprehensive collection of Python decorators and utility functions to enhance your development workflow.
Installation
pip install python-wrap
Features
PythonWrap provides a rich set of decorators that can be used either as decorators or as standalone functions:
Performance & Profiling
@timing: Measure function execution time@profile: Profile function performance@benchmark: Compare execution times@measure_memory: Track memory usage
Error Handling & Reliability
@retry: Retry failed operations@retry_on_exception: Retry on specific exceptions@timeout: Set execution time limits@revert_on_failure: Automatic state rollback on failure
Caching & Optimization
@memoize: Cache function results@cache: Time-based result caching@once: Single execution guarantee
Debugging & Logging
@log_args: Log function arguments@log_return: Log return values@trace: Log call stack traces@audit: Comprehensive function call auditing
Type Safety & Validation
@check_type: Runtime type checking@validate_args: Custom argument validation
Development Tools
@deprecate: Mark deprecated functions@no_debug: Disable debug output@mock_data: Easy data mocking@rate_limit: Control execution frequency
Concurrency
@run_in_thread: Asynchronous execution@transactional: Atomic operations
Usage Examples
Using as Decorators
from python_wrap import timing, retry, memoize
# As a decorator
@timing
def slow_operation():
time.sleep(1)
return "Done"
# As a decorator with parameters
@retry(max_attempts=3, delay=1.0)
def unreliable_operation():
return api_call()
# Simple decorator
@memoize
def fibonacci(n):
if n < 2:
return n
return fibonacci(n-1) + fibonacci(n-2)
Using as Functions
from python_wrap import timing, retry, memoize
# Using timing as a function
def slow_operation():
time.sleep(1)
return "Done"
result = timing(slow_operation)()
# Using retry as a function
def unreliable_operation():
return api_call()
result = retry(unreliable_operation, max_attempts=3, delay=1.0)()
# Using memoize as a function
def fibonacci(n):
if n < 2:
return n
return fibonacci(n-1) + fibonacci(n-2)
memoized_fib = memoize(fibonacci)
result = memoized_fib(10)
Advanced Usage
from python_wrap import validate_args, check_type, timeout
# As decorators
@validate_args(x=lambda x: x > 0, y=lambda y: y < 100)
def process_numbers(x, y):
return x + y
@check_type(name=str, age=int)
def create_user(name, age):
return {"name": name, "age": age}
# As functions
def long_running_task():
process_large_dataset()
timed_task = timeout(5)(long_running_task)
result = timed_task()
Combining Multiple Functions
from python_wrap import timing, retry, log_args
# As decorators
@timing
@retry(max_attempts=3)
@log_args
def complex_operation(x, y):
return expensive_calculation(x, y)
# As functions
def complex_operation(x, y):
return expensive_calculation(x, y)
# Compose functions
monitored_op = timing(retry(log_args(complex_operation), max_attempts=3))
result = monitored_op(1, 2)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for python-wrap 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| python_wrap-0.1.0.tar.gz | 8.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| python_wrap-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.9 kB
Release files / python_wrap-0.1.0.tar.gz
| Download URL | python_wrap-0.1.0.tar.gz |
|---|---|
| Size | 8.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
41c843532efc80255545ec1466a91d595563f2481dc0f578fd7d7fbc265958cc
|
|
BLAKE2b-256 checksum How to use checksums |
ba118ca27f2ce3a133b935e63fb7f9dac50f78c4fbad5be5c1f3342d80f83a94
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.5 CPython/3.8.18 Linux/6.8.0-1017-azure
|
Release files / python_wrap-0.1.0-py3-none-any.whl
| Download URL | python_wrap-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8e6efc9d782943abebefc67996fa0575d2d8315466e751cbed5ae374a8edc8bd
|
|
BLAKE2b-256 checksum How to use checksums |
09cdd7b5f7e4e14aed2b6a4f26da3dcca5070898d7e3799fd72b41f107ead5d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.5 CPython/3.8.18 Linux/6.8.0-1017-azure
|
Security for python-wrap 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.