Skip to main content

Add your description here

Project description

utde

A collection of utility decorators to simplify my life.

Persist

Instead of recomputing an expensive function annotate it with a generic_persist decorator. This decorator allows you to specify:

- key_or_fn: Either a string or a function
that generates a string from the wrapped_fn args
- load_fn: A function that is used to retrieve
stored data from key
- store_fn: A function that is used to store
the results of the "expensive" function call so that
it can be loaded next time instead
from utde.persist import generic_persist

cache = dict()

def key_fn(day_str):
    year, month, day = day_str.split("-")
    return f"{year}/{month}/{day}"

def load_fn(key):
    if key in cache:
        return cache[key]

def store_fn(x, key):
    cache[key] = x

@generic_persist(key_fn, load_fn, store_fn)
def wrapped_fn(x, day_str):
    print("Imagine an expensive operation")
    return x * 2

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

utde-0.1.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

utde-0.1.0-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file utde-0.1.0.tar.gz.

File metadata

  • Download URL: utde-0.1.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for utde-0.1.0.tar.gz
Algorithm Hash digest
SHA256 389742acb160e07c4d62c1c49d8068151532e5cac6581976d82f9639b3a6327a
MD5 6c734838a02d847be02eeadad85efbfc
BLAKE2b-256 f4b6ea400d1079d44994dfd0f8c73032003249c627a62447d300a2dbed35c110

See more details on using hashes here.

File details

Details for the file utde-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: utde-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for utde-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0fc306a0c83aef106ca7b5446b1619dd1bd4628590c0323989d2e46afb17883f
MD5 5dc48205aff8834b63bbd3a8f90527be
BLAKE2b-256 5531e0b78e5865e7d361dd3f7b30fe4e288e0114e869c86e562e014a2bc0b812

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