Python Utils is a module with some convenient utilities not included with the standard Python install
Project description
Python Utils is a collection of small Python functions and classes which make common patterns shorter and easier. It is by no means a complete collection but it has served me quite a bit in the past and I will keep extending it.
One of the libraries using Python Utils is Django Utils.
Documentation is available at: https://python-utils.readthedocs.org/en/latest/
Links
The source: https://github.com/WoLpH/python-utils
Project page: https://pypi-hypernode.com/pypi/python-utils
Reporting bugs: https://github.com/WoLpH/python-utils/issues
Documentation: https://python-utils.readthedocs.io/en/latest/
My blog: https://wol.ph/
Requirements for installing:
six any recent version
Installation:
The package can be installed through pip (this is the recommended method):
pip install python-utils
Or if pip is not available, easy_install should work as well:
easy_install python-utils
Or download the latest release from Pypi (https://pypi-hypernode.com/pypi/python-utils) or Github.
Note that the releases on Pypi are signed with my GPG key (https://pgp.mit.edu/pks/lookup?op=vindex&search=0xE81444E9CE1F695D) and can be checked using GPG:
gpg –verify python-utils-<version>.tar.gz.asc python-utils-<version>.tar.gz
Quickstart
This module makes it easy to execute common tasks in Python scripts such as converting text to numbers and making sure a string is in unicode or bytes format.
Examples
To extract a number from nearly every string:
from python_utils import converters
number = converters.to_int('spam15eggs')
assert number == 15
number = converters.to_int('spam')
assert number == 0
number = converters.to_int('spam', default=1)
assert number == 1
number = converters.to_float('spam1.234')
To do a global import programmatically you can use the import_global function. This effectively emulates a from … import *
from python_utils.import_ import import_global
# The following is the equivalent of `from some_module import *`
import_global('some_module')
Or add a correclty named logger to your classes which can be easily accessed:
class MyClass(Logged):
def __init__(self):
Logged.__init__(self)
my_class = MyClass()
# Accessing the logging method:
my_class.error('error')
# With formatting:
my_class.error('The logger supports %(formatting)s',
formatting='named parameters')
# Or to access the actual log function (overwriting the log formatting can
# be done n the log method)
import logging
my_class.log(logging.ERROR, 'log')
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 python-utils-2.6.0.tar.gz
.
File metadata
- Download URL: python-utils-2.6.0.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.7.1 requests/2.26.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/2.7.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a4402fa07994c715d66c8d50ca721e3394d7a4e098163c170e657aa09d6bfb5 |
|
MD5 | 18a5867202396429ad04b08df080c878 |
|
BLAKE2b-256 | 2f49d5e36c28ada90b486250a87bdcbbe20e110a5d2c373b56d108a358776876 |
File details
Details for the file python_utils-2.6.0-py2.py3-none-any.whl
.
File metadata
- Download URL: python_utils-2.6.0-py2.py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.7.1 requests/2.26.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/2.7.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1eec84860463b0b551c8bc222c1a52c66f1d502fa46f7952b77de77bda66efe6 |
|
MD5 | 251da03f63a27ec17c3f39018457a9a4 |
|
BLAKE2b-256 | 7bbee41d6d1ae5fa74bb4b9523a5e1f38c03b0d9ce780f52e4f2264b2697a1d3 |