Skip to content

py_misc_utils

CI Docs PyPI version License: Apache-2.0 Python 3.12+

A collection of Python utility APIs — a toolbox of battle-tested helpers covering executors, async task management, object caching, filesystem abstraction, data structures, HTTP clients and servers, type casting and validation, logging, pipeline processing, and many more general-purpose helpers.

Install

The library can be installed using PyPi:

$ pip install python-misc-utils

Or directly from the Github repository:

$ pip install git+https://github.com/davidel/py_misc_utils.git

Quick start

A few taste-of-the-API examples. See the full documentation for the complete reference.

Executor

import py_misc_utils.executor as xe

ex = xe.Executor(max_threads=4, min_threads=1, name_prefix='Demo')
res = ex.submit_result(lambda a, b: a + b, 2, 3)
assert res.wait() == 5
ex.submit(print, 'fire and forget')
ex.wait_for_idle()
ex.shutdown()

Logging

The alog module extends the standard logging with extra verbosity levels (SPAM, VERBOSE, DEBUG0..3) and compact log headers.

import py_misc_utils.alog as alog

alog.basic_setup(log_level=alog.INFO)
alog.info("processing started")
alog.debug2("verbose diagnostics")

Ordered set

from py_misc_utils import ordered_set

oset = ordered_set.OrderedSet([3, 1, 3, 2])
list(oset.values())  # [3, 1, 2] -- insertion order kept
oset.add(5)

Async HTTP fetcher

from py_misc_utils import http_async_fetcher as haf

with haf.HttpAsyncFetcher(num_workers=2) as fetcher:
  fetcher.enqueue("https://example.com/data.bin")
  results = dict(fetcher.iter_results())

Pipeline

from py_misc_utils import pipeline

pline = pipeline.Pipeline(lambda x: x + 1, lambda x: x * 10)
print(pline(5))  # 60

Documentation

The full API reference, auto-generated from the source docstrings, is published at davidel.github.io/py_misc_utils.