Skip to main content

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

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 corrects 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

python_utilz-0.1.3.tar.gz (29.6 kB view details)

Uploaded Source

Built Distribution

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

python_utilz-0.1.3-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file python_utilz-0.1.3.tar.gz.

File metadata

  • Download URL: python_utilz-0.1.3.tar.gz
  • Upload date:
  • Size: 29.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.9

File hashes

Hashes for python_utilz-0.1.3.tar.gz
Algorithm Hash digest
SHA256 ef4846ff84dcc79145adeb753b325dfb74c3e7562fb42443fcef7b0b333a25aa
MD5 cc52da51716826f61ecadb4b71f44d5c
BLAKE2b-256 312bbaf6a9c8f1c892b12029bcb3231692a0db660ca82dd4a952e8b91d4923d3

See more details on using hashes here.

File details

Details for the file python_utilz-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for python_utilz-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4ce5716ec83222a9c812c755eb831cc5f0a71f6ea35da930eceaaae2db8a15ab
MD5 8956bb003d10433e9801ef3e777af803
BLAKE2b-256 cfadfe08305da4be0d4b4b611c11737c4e94d7e00d22568eb89a445f63cf10b3

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