🐣💻 Developing Tools
The "Developing Tools" project is a Python 🐍 package designed to enhance the development process by providing a collection of tools/utilities aimed at improving debugging, performance measurement, error handling, ...
These tools ⚒️ are intended to assist developers in identifying performance bottlenecks, handling transient errors, and gaining insights into function behavior during runtime. The package is easy to install and use, making it a good addition to any Python developer's toolkit 🚀.
Table of Contents
📥 Installation
pip install developing-tools
💻 Utilization
Execution Time
The execution_time decorator allows you to measure the execution time of a function. The decorator has one parameter:
output_decimals: Number of decimal places to display in the output. Default is 10.
from time import sleep
from developing_tools.functions import execution_time
@execution_time(output_decimals=2)
def too_slow_function() -> None:
sleep(2)
too_slow_function()
# >>> Function "too_slow_function" took 2.00 seconds to execute.
Retry It
The retryit decorator allows you to retry a function multiple times in case of failure. The decorator has two parameters:
attempts: The number of attempts to execute the function, if None the function will be executed indefinitely. Default is None.delay: The delay between attempts in seconds, if a tuple is provided the delay will be randomized between the two values. Default is 5 seconds.raise_exception: If True the decorator will raise the last caught exception if the function fails all attempts. Default is True.valid_exceptions: A tuple of exceptions that the decorator should catch and retry the function, if None the decorator will catch all exceptions. Default is None.
from developing_tools.functions import retryit
@retryit(attempts=3, delay=0.5, raise_exception=True, valid_exceptions=(ValueError,))
def failing_function() -> None:
raise ValueError('This function always fails!')
failing_function()
# >>> Function failed with error: "This function always fails!". Retrying in 0.50 seconds ...
# >>> Attempt [2/3] to execute function "failing_function".
# >>> Function failed with error: "This function always fails!". Retrying in 0.50 seconds ...
# >>> Attempt [3/3] to execute function "failing_function".
# >>> Function failed with error: "This function always fails!". No more attempts.
# Traceback (most recent call last):
# File "<file_path>/main.py", line 7, in <module>
# failing_function()
# File "<file_path>/developing_tools/functions/retryit.py", line 132, in wrapper
# raise exception
# File "<file_path>/developing_tools/functions/retryit.py", line 124, in wrapper
# return function(*args, **kwargs)
# ^^^^^^^^^^^^^^^^^^^^^^^^^
# File "<file_path>/main.py", line 5, in failing_function
# raise ValueError('This function always fails!')
# ValueError: This function always fails!
Print Parameters
The print_parameters decorator allows you to print the parameters of a function. The decorator has two parameters:
show_types: If True the decorator will print the types of the parameters. Default is False.include_return: If True the decorator will print the return value of the function. Default is True.
from developing_tools.functions import print_parameters
@print_parameters(show_types=True, include_return=True)
def normal_function(a: int, b: str, c: int, d) -> str:
return a
normal_function(1, 'Hello', c=3, d=4)
# >>> Positional arguments:
# >>> Argument 1: value "1", type int
# >>> Argument 2: value "Hello", type str
# >>>
# >>> Keyword arguments:
# >>> Argument c: value "3", supposed type int, real type int
# >>> Argument d: value "4", supposed type Any, real type int
# >>>
# >>> Return value:
# >>> "1", supposed type str, real type int
Timeout
The timeout decorator allows you to set a maximum execution time for a function. The decorator has one parameter:
seconds: The maximum number of seconds the function is allowed to execute before raising a TimeoutError. Default is 10 seconds.
from time import sleep
from developing_tools.functions import timeout
@timeout(seconds=2)
def too_slow_function() -> None:
sleep(5)
too_slow_function()
# >>> TimeoutError: Function too_slow_function exceeded the 2 seconds timeout.
🔑 License
This project is licensed under the terms of the MIT license.
Metadata
Release files for developing-tools 2024.10.22
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| developing_tools-2024.10.22.tar.gz | 12.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| developing_tools-2024.10.22-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.7 kB
Release files / developing_tools-2024.10.22.tar.gz
| Download URL | developing_tools-2024.10.22.tar.gz |
|---|---|
| Size | 12.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dd39613ade48358e2d11a4fd05c6bd3601bc3a7e357be7b502ee0da620826bce
|
|
BLAKE2b-256 checksum How to use checksums |
765788300b031be9471bdd7ed068be1af8d708f2a85fca6670556f5e4e3a6eb1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.7
|
Release files / developing_tools-2024.10.22-py3-none-any.whl
| Download URL | developing_tools-2024.10.22-py3-none-any.whl |
|---|---|
| Size | 14.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
84510b1fa89e733b6442c49ef4f415a56f6b71fdc8ddc97abec7c2923044d0e1
|
|
BLAKE2b-256 checksum How to use checksums |
f7d7db250943327397ace6e9a55686c9dce3e66b1964603a95aafdcfcc29425d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.7
|