Useful Python Utils
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.python.org/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.python.org/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')
Metadata
Release files for python-utils 2.5.3
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 | Actions |
|---|---|---|---|---|
| python-utils-2.5.3.tar.gz | 49.1 kB | Without provenance | Details for python-utils-2.5.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| python_utils-2.5.3-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for python_utils-2.5.3-py2.py3-none-any.whl |
Total release size: 61.9 kB
Release files / python-utils-2.5.3.tar.gz
| Download URL | python-utils-2.5.3.tar.gz |
|---|---|
| Size | 49.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5453db694f92aafc3f3285b1526541dee6de0b9344d6fd65b6bac8b68ef120bf
|
|
BLAKE2b-256 checksum How to use checksums |
151763138862f2e202fc53729f5bf9573efc0e1ca2323daf2ff0f2d2819ec866
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.8
|
Release files / python_utils-2.5.3-py2.py3-none-any.whl
| Download URL | python_utils-2.5.3-py2.py3-none-any.whl |
|---|---|
| Size | 12.8 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
e4c52aa767774f06b28fb9d665b4104c9a64d7c2c45fedf4f79c1bda6576a1eb
|
|
BLAKE2b-256 checksum How to use checksums |
59e808e87ec90000f971c86c96a0f2ac3a29a72a2f77cb9247e40c3b2df97d24
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.8
|
Security for python-utils 2.5.3
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.