Skip to main content

olutils

travis codecov PyPI Latest Release

Introduction

About

The module olutils provide common tools to simplify daily coding. It includes:

  • object storing (.csv, .json, .pickle, .txt)
  • convenient collection (deep defaultdict, lazy list, identity/prod functions)
  • conversion functions (for datetime, dictionaries, errors)
  • sequencing helpers (iteration with progress display, wait until predicate)
  • parameter management
  • and more...

Installation

One can install olutils using pip install command: pip install olutils

Usage

Object Storing

  • Storage: save and load
import olutils

my_dict = {'key_1': "value_1", 'key_2': 2}
my_rows = [{'col_1': 11, 'col_2': 21}, {'col_1': 21, 'col_2': 22}]

# Saving objects in output directory (automatically created)
olutils.save(my_dict, "output/my_dict.json")
olutils.save(my_rows, "output/my_rows.csv")
olutils.save(my_rows, "output/my_rows.unknown", mthd="json")

# Loading objects from save outputs
my_loaded_dict = olutils.load("output/my_dict.json")
my_loaded_rows = olutils.load("output/my_rows.csv")
my_loaded_rows_ = olutils.load("output/my_rows.unknown", mthd="json")

Collections

  • deepdefaultdict
import olutils
from olutils.conversion import str2dt

# Building a deep default dict with datetimes as values
flights = olutils.deepdefaultdict(lambda x: None, depth=2)

# Filling it
flights['Paris-NY']['departure'] = str2dt("2019-01-15 08:00+01:00")
flights['Paris-NY']['arrival'] = str2dt("2019-01-15 10:30-05:00")
flights['NY-Paris']['departure'] = str2dt("2019-01-17 23:00-05:00")
flights['NY-Paris']['arrival'] = str2dt("2019-01-15 11:00+01:00")

flights.pprint()
  • LazyList
import olutils

print(olutils.LazyList(range(10000), 10))
  • functions: prod and identity
import olutils

# Operations
assert olutils.prod([2, 7]) == 14
assert olutils.identity(1) == 1
  • singleton:
import olutils

class MyClass(metaclass=olutils.Singleton):
    pass

instance = MyClass()
assert instance is MyClass()

More

  • Explicit iteration
import olutils


print("Iterating on very long iterable:")
for elem in olutils.countiter(range(int(10e6)), vbatch=100, prefix=". "):
    # One-Line display of progress every 100 iteration
    pass
  • Compare
import olutils

# Comparison
l1 = [1, 2, "hi", "bye"]
l2 = [3, "bye", "bye bye", 2]
assert olutils.content_diff(l1, l2) == {
    'common': {2, "bye"},
    'minus': {1, "hi"},
    'plus': {3, "bye bye"},
}
  • Pretty displays
import olutils

assert olutils.err2str(ValueError("Message")) == "ValueError - Message"
l = [1, 2, 3, 4, 5]
imp_l = olutils.lazy_content(l, 4)
assert str(imp_l) == '[1, 2, Ellipsis, 5]'
dic = {
    'values': l,
    'info': {
        'name': "Some example",
        'also': "This is awesome (kinda)",
    }
}
print(f"Dictionary used: {dic}")
print(f"Dictionary to pretty string:")
def leafconv(x):
    return (
        str(olutils.lazy_content(x, 5))
        if isinstance(x, list)
        else str(x)
    )
print(olutils.dict2str(dic, leafconv=leafconv))

Metadata

Release files for olutils 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for olutils 2.1.0
File Size Uploaded Provenance
olutils-2.1.0.tar.gz 28.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for olutils 2.1.0
File Interpreter ABI Platform
olutils-2.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 65.9 kB

Release files / olutils-2.1.0.tar.gz

Download URL olutils-2.1.0.tar.gz
Size 28.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0fb863664fcabcb7b09b7d98762444c9708daeebb435ecb7c80904f3c9548268
BLAKE2b-256 checksum
How to use checksums
42075306f32b288bae5eb86c5bae445369a5e024a6b89f8de1ae28753f98ff11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.9.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

Release files / olutils-2.1.0-py3-none-any.whl

Download URL olutils-2.1.0-py3-none-any.whl
Size 37.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4b6e171282b0a1782e2ccd4484e11fcbbc856feb6c2b5c5bcbeb96319fe44723
BLAKE2b-256 checksum
How to use checksums
3020dc1383c37ebf1989d9425383b1179da24e9cf86fcf866c4b67afe0503083
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.9.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

Security for olutils 2.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page