Python Utility Decorators
Project description
pyutilator
pyutilator is an open source Python package that provides decorators for utility operations. Decorators are a powerful tool in Python, allowing you to modify the behavior of a function or class. pyutilator makes it easy to add common utility functions to your code, such as timing or logging, by using simple decorators.
Installation
You can install pyutilator using pip:
pip install pyutilator
Available Decorators
Decorator | Description |
---|---|
@print_args | Print function Arguments |
@print_kwargs | Print Function Key Word Arguments |
@print_return_value | Print Function Return Value |
Usage
Here's an example of how you can use the print_args decorator to log the function arguments:
from pyutilator.print.print_args import print_args
@print_args
def add(a,b):
print("Sum : %d" %(a+b))
add(1,2)
# output
Function Arguments : (1, 2)
Sum : 3
Here's another example of how you can use the print_kwargs decorator to log the function key word arguments:
from pyutilator.print.print_kwargs import print_kwargs
@print_kwargs
def add(a,b):
print("Sum : %d" %(a+b))
add(a=1,b=2)
# output
Function Key Word Arguments : {'a': 1, 'b': 2}
Sum : 3
The decorators can also be chained to perform different utility operations on the same function. This example shows how you can use both print_args and print_kwargs decorators to print function arguments and key word arguments.
from pyutilator.print.print_kwargs import print_kwargs
from pyutilator.print.print_args import print_args
@print_kwargs
@print_args
def add(a,b):
print("Sum : %d" %(a+b))
add(1,b=2)
# output
Function Key Word Arguments : {'b': 2}
Function Arguments : (1,)
Sum : 3
Contributing
If you're interested in contributing to pyutilator, please take a look at our contributing guidelines. We welcome all contributions, whether they're bug fixes, new features, or documentation improvements.
- Fork it (https://github.com/antoprince001/pyutilator/fork)
- Create your feature branch (
git checkout -b feature/fooBar
) - If you've added code that should be tested, add tests.
- Ensure the test suite passes. (
pytest
) - Commit your changes (
git commit -m 'Add some fooBar'
) - Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request
License
pyutilator is released under the MIT License.
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
File details
Details for the file pyutilator-1.0.0.tar.gz
.
File metadata
- Download URL: pyutilator-1.0.0.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e18bbe2cbbb22e3f025e6b2504a9f8584b66f4eee14796413e58d2376f05335b |
|
MD5 | 2f3555fc6cd481adf1b2c256379e5cdf |
|
BLAKE2b-256 | 06612129d972bf6a1868f659b4f0a7ae2b63d9eb677ed49baed636fa3f538459 |
File details
Details for the file pyutilator-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: pyutilator-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb10476a4960f1eb108258b3524b547735d6f08d4e3f61a85055b7535cfee804 |
|
MD5 | 4c6af60237cf2b300a3a50fd64ec34a7 |
|
BLAKE2b-256 | 929658a25bd7a14959e09720e3361d5a1c5d7f9afd3e72f91f14ae168a635db3 |