Skip to main content
https://travis-ci.org/WoLpH/python-utils.svg?branch=master https://coveralls.io/repos/WoLpH/python-utils/badge.svg?branch=master

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/

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')

Release files for python-utils 2.3.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 python-utils 2.3.0
File Size Uploaded
python-utils-2.3.0.tar.gz 19.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-utils 2.3.0
File Interpreter ABI Platform
python_utils-2.3.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 32.1 kB

Release files / python-utils-2.3.0.tar.gz

Download URL python-utils-2.3.0.tar.gz
Size 19.4 kB
Tags Source
SHA-256 checksum
How to use checksums
34aaf26b39b0b86628008f2ae0ac001b30e7986a8d303b61e1357dfcdad4f6d3
BLAKE2b-256 checksum
How to use checksums
3095d01fbd09ced38a16b7357a1d6cefe1327b9273885bffd6371cbec3e23af7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / python_utils-2.3.0-py2.py3-none-any.whl

Download URL python_utils-2.3.0-py2.py3-none-any.whl
Size 12.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
e25f840564554eaded56eaa395bca507b0b9e9f0ae5ecb13a8cb785305c56d25
BLAKE2b-256 checksum
How to use checksums
eba019119d8b7c05be49baf6c593f11c432d571b70d805f2fe94c0585e55e4c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

4.0.1

2 release files

4.0.0

2 release files

3.9.1

2 release files

3.9.0

2 release files

3.8.2

2 release files

3.8.1

2 release files

3.8.0

2 release files

3.7.0

2 release files

3.6.1

2 release files

3.6.0

2 release files

3.5.2

2 release files

3.5.1

2 release files

3.5.0

2 release files

3.4.5

2 release files

3.4.4

2 release files

3.4.3

2 release files

3.4.2

2 release files

3.4.1

2 release files

3.4.0

2 release files

3.3.3

2 release files

3.3.2

2 release files

3.3.1

2 release files

3.3.0

2 release files

3.2.3

2 release files

3.2.2

2 release files

3.2.1

2 release files

3.2.0

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.7.1

2 release files

2.7.0

2 release files

2.6.3

2 release files

2.6.2

2 release files

2.6.1

2 release files

2.6.0

2 release files

2.5.6

2 release files

2.5.5

2 release files

2.5.3

2 release files

2.5.2

2 release files

2.5.1

2 release files

2.5.0

2 release files

2.4.0

2 release files

This release

2.3.0 This release

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.6.2

1 release file

1.6.1

1 release file

1.6.0

1 release file

1.5.2

1 release file

1.5.1

1 release file

1.5.0

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.1

2 release files

1.0

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