Skip to main content

Utilities for Python

Project description

py-utls

Utilities for Python

PyPI GitHub tag (latest by date) GitHub last commit GitHub issues GitHub

py-utls is a small Python repository where I put all the useful stuff I regularly need in my projects.
Feel free to use at your discretion with the appropriate license mentions.

NB: I've developed the same kind of libraries for both Go and TypeScript.

Usage

pip install py-utls

This repository contains the following modules:

  • hex:
    • from_hex: builds the byte array from a string;
    • to_hex: creates the hexadecimal representation of a byte array;
  • list:
    • chunk: split a list into chunks of a maximum size;
    • flatten: transforms a list of list of items to a list of items;
  • number:
    • euclidean_division: compute the euclidean division of the passed integers.
from pyutls.hex import from_hex, to_hex
from pyutls.list import chunk, flatten
from pyutls.number import euclidean_division

# Hex utilities
barray = from_hex('1234abcd')
hex_string = to_hex(barray)
assertEqual(hex_string == '1234abcd')

# Flatten a list of list
chunks = chunk(some_list, size)
flat_list = flatten(chunks)
assertListEqual(flat_list == some_list)

# Euclidean division
quotient, remainder = euclidean_division(numerator, denominator)
assertEqual(quotient * denominator + remainder == numerator)

It also constains a CustomLogger class (see its documentation for usage):

from pyutls import CustomLogger

logger = CustomLogger()
logger.with_time("This test line should appear in test logs!")

Tests

Eventually, add a setup step:

$ git clone https://github.com/cyrildever/py-utls.git
$ cd py-utls/
$ python3 -m venv venv
$ source venv/bin/activate
$ pip install build twine setuptools

Then, proceed to testing:

$ python3 -m unittest discover

License

These modules are distributed under a MIT license.
See the LICENSE file.


© 2022-2025 Cyril Dever. All rights reserved.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_utls-0.3.1.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_utls-0.3.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file py_utls-0.3.1.tar.gz.

File metadata

  • Download URL: py_utls-0.3.1.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for py_utls-0.3.1.tar.gz
Algorithm Hash digest
SHA256 b49a0134a3d83ddc2a1f934e92f70b5fe66d0384f3fee0191c0fc4906993d663
MD5 6467cbb301564ee0fa22d8d3f408732b
BLAKE2b-256 b3eabdcd6611febdc76c6530d508784960e850574f65c39b28de4bb46fe4f0c9

See more details on using hashes here.

File details

Details for the file py_utls-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: py_utls-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for py_utls-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ee2b362e8a9af33bd3b562c2bca2bb1b39ced3e6eb3511631079b0e5fac2445f
MD5 991f20a4acffdc0ac421e56577c04182
BLAKE2b-256 e25b575f2888ff56b1de5b091c164a1ed4694032b37f6c2a21eacdc609b2aa22

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page