Skip to main content

nix-python-utils

Description: A collection of versatile classes, methods and decorators that I frequently use across my work projects.

Content

##Install

pip install nix-python-utils

Classes

For use classes you need to import them from the package:

import nix.classes as classes
Method Parameters Returns Description
IO.read_file - file_path (str): The path to the file to read. str Reads a file from the specified path and returns its content as a string.
IO.write_file - file_path (str): The path to the file to write to. None Writes the given content to the specified file.
- content (str): The content to write to the file.
IO.create_folder_if_not_exists - folder_path (str): The path to the folder to create. None Creates a folder at the specified path if it does not already exist.

Decorators

For use decorators you need to import them from the package:

import nix.utils.decorators as decorators
Decorator Arguments Description
@retry - max_retries (int, default=3)
- delay (int, default=2)
- exceptions (Exception or tuple of Exceptions, default=Exception)
- backoff_factor (int, default=1)
- logger (Logger, optional)
A decorator that retries a function upon failure. You can customize the maximum number of retries, the delay between retries, the type of exceptions to catch, and the backoff factor to increase the delay with each retry. If a logger is provided, exceptions are logged.
@thread_pool - num_threads (int, default=4)
- exceptions (Exception or tuple of Exceptions, default=Exception)
- raise_first_exception (bool, default=False)
- logger (Logger, optional)
A decorator that runs a function in a thread pool with a specified number of threads. It collects results from all tasks and returns them as a list. It also handles exceptions, with an option to re-raise the first exception or just log it.
@handle_exception - handler (Callable[[Exception], Any], optional)
- exceptions (Exception or tuple of Exceptions, default=Exception)
- default_value (Any, optional)
- raise_exception (bool, default=False)
- logger (Logger, optional)
A decorator for handling exceptions in a function. You can specify a custom exception handler, the type of exceptions to catch, a default return value if exceptions occur, and whether to re-raise exceptions. Logging is optional and can be controlled with a logger. It also supports additional arguments and keyword arguments for the exception handler.

Licence

This project is licensed under the MIT License. See the LICENSE file for more details.

Release files for nix-python-utils 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nix-python-utils 0.1.0
File Size Uploaded
nix_python_utils-0.1.0.tar.gz 7.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nix-python-utils 0.1.0
File Interpreter ABI Platform
nix_python_utils-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.9 kB

Release files / nix_python_utils-0.1.0.tar.gz

Download URL nix_python_utils-0.1.0.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e1e16723f3f701ad689c554e33d05f1e12b81b5ac4710460b7fe6fb89783ccca
BLAKE2b-256 checksum
How to use checksums
5bfef08dfaadc665f6c33573489b929a13be08522f3138729577d3174f1f58f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.8

Release files / nix_python_utils-0.1.0-py3-none-any.whl

Download URL nix_python_utils-0.1.0-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d0d60758a84543e478f396128831d92686415015f8a67042641f4e536f67a002
BLAKE2b-256 checksum
How to use checksums
a2305f59cfb429e85a460fc272124bc0fe86c9af5ba0eda365935eb3c1f7941b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.8

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page