cyrildever / py-utls

Utilities for Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.
from pyutls.hex import from_hex, to_hex
from pyutls.list import chunk, flatten

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

Tests

$ python3 -m unittest discover

License

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


© 2022-2024 Cyril Dever. All rights reserved.

About

Utilities for Python

License:MIT License


Languages

Language:Python 94.6%Language:Shell 5.4%