Set of handy python utilities
Project description
python-utilz
Set of handy python utilities.
Installation
pip install python-utilz
Contents
- Get size of an object
- Convert exception to string
- Check UUID corrects without casting
- Human-readable time
- Human-readable size
- Separate digits
- Now
- Config from env
Get size of an object
Returns total size in bytes (when you do not want full-fledged library for this).
import python_utilz as pu
print(pu.get_size([1, 2, 3]))
# 172
Convert exception to string
Show more info than just str(exc).
import python_utilz as pu
print(repr(pu.exc_to_str(TimeoutError('test'))))
# 'TimeoutError: test'
Check UUID is correct without casting
When you want to check UUID, but do not want try-except on UUID(value).
import python_utilz as pu
print(pu.is_valid_uuid('lol-kek'))
# False
Human-readable time
Created to display difference between two timestamps.
import python_utilz as pu
print(repr(pu.human_readable_time(9999999)))
# '16w 3d 17h 46m 39s'
print(repr(pu.htime(1742579085.0 - 1741924401.0)))
# '1w 13h 51m 24s'
Human-readable size
Created to display total amount of bytes in something.
import python_utilz as pu
print(repr(pu.human_readable_size(999999999)))
# '953.7 MiB'
print(repr(pu.hsize(10000000000)))
# '9.3 GiB'
Separate digits
When you want number to be more readable.
import python_utilz as pu
print(repr(pu.sep_digits(123456789)))
# '123 456 789'
Now
Returns current datetime in UTC timezone.
import python_utilz as pu
print(pu.now())
# 2025-03-21 18:13:34.954740+00:00
Config from env
Creates simple config from environment variables. Smaller variant of pydantic-settings.
from dataclasses import dataclass
import python_utilz as pu
@dataclass
class Database(pu.BaseConfig):
url: str
timeout: int
# export MY_VAR__URL=https://site.com
# export MY_VAR__TIMEOUT=10
config = pu.from_env(Database, env_prefix='my_var')
print(config)
# Database(url='https://site.com', timeout=10)
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_utilz-0.1.4.tar.gz.
File metadata
- Download URL: python_utilz-0.1.4.tar.gz
- Upload date:
- Size: 30.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04749471a7b45bcaf849362ea5054bde406f9c401f9fc552b11a0bf19c518e18
|
|
| MD5 |
401d8ec4641569d455782f67a0d70aff
|
|
| BLAKE2b-256 |
303b87ed9f9e0f09d20e496a766052a0aff2b9299ae9641208cf96975d773bec
|
File details
Details for the file python_utilz-0.1.4-py3-none-any.whl.
File metadata
- Download URL: python_utilz-0.1.4-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b84fdb3cb353798fc411fbdf7151b83814dfe0b08827638f3167b4c1763c0c52
|
|
| MD5 |
eb96232d82d49e0315fc45398c19ce2a
|
|
| BLAKE2b-256 |
5da027002db854bf02faeab9684517a29dd03ce5ed4018c5ba346855fc125c31
|