Skip to main content

Pickling and unpickling of function arguments

Project description

sylte

Testing and linting codecov GitHub release (latest by date including pre-releases) PyPI

Sylte provides a decorator that stores function arguments as a pickle file in a central location, and functions for retrieving those arguments later on, so that the function can be re-invoked with the same args. Useful when writing or debugging a function that exists somewhere near the end of a long-running pipeline.

Installation

Using poetry:

poetry add sylte

Using pipenv:

pipenv install sylte

Using pip:

pip install sylte

Usage

Let's say we have a function transform that we want to debug or modify. We will have to call it several times to see how it behaves with real data. It's normally called as part of a long-running pipeline, and we don't want to have to wait for this pipeline every time. We could write a unit-test, but perhaps we aren't yet sure how the output will look, and perhaps the input-data is complex and time-consuming to recreate in a test, and we'd prefer to do that when the function is finalized, to avoid having to repeatedly modify the test as the function is modified.

Enter sylte. By applying the @sylt decorator to the function and running the pipeline once, the args are recorded, and can be retrieved later.

from sylte import sylt

@sylt
def transform(this_huge_df, this_other_huge_df, this_object_with_lots_of_attributes):
    ...

The arg set will be stored in a pickle file in the default cache location for the os. The location can be seen by running from sylte import CACHE_DIR; print(CACHE_DIR). To use a different location than the default, specify the location with the environment variable SYLTE_CACHE_DIR.

The file name will have the format <file name>-<function name>-<timestamp>.pickle.

The function latest will retrieve an unsylt the latest arg set, returning a tuple with args and kwargs.

>>> from sylte import latest
...
>>> args, kwargs = latest()
>>> transform(*args, **kwargs)

show returns a list of all sylted arg sets:

>>> from sylte import show
...
>>> show()
['demo-transform-2022-01-14-15-08-59',
 'demo-transform-2022-01-14-15-12-33',]

unsylt unsylts and returns the arg set with the specified name as output by show, i.e. the filename with the extension omitted:

>>> from sylte import unsylt
...
>>> args, kwargs = unsylt('demo-add-2022-01-14-15-08-59')
>>> transform(*args, **kwargs)

clear deletes all previously sylted arg sets:

>>> from sylte import clear, show
...
>>> clear()
>>> show()
[]

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

sylte-0.0.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

sylte-0.0.1-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file sylte-0.0.1.tar.gz.

File metadata

  • Download URL: sylte-0.0.1.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.10.0 Linux/5.11.0-1025-azure

File hashes

Hashes for sylte-0.0.1.tar.gz
Algorithm Hash digest
SHA256 bde8d84c183d104e06875f028358c2e0069561e7ac216ae659d6ce115255c88f
MD5 69f7b5e37aff7cad97b68802deb18f4d
BLAKE2b-256 163475867dfbda75d6f372da86c96c1a3548a4027466ce658dcaa8ef695f46d5

See more details on using hashes here.

File details

Details for the file sylte-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: sylte-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.10.0 Linux/5.11.0-1025-azure

File hashes

Hashes for sylte-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 72c85b9bda21f3bc3d44cd3308832db23b3d5d5fbc7749e7a5c5db5daf44abf2
MD5 eaa66992c1732d06d2c13120b5ec38e3
BLAKE2b-256 66f46afe7cd74452f21488fabf2ad7846f1b47b6a100c81f2ae05f000b4657d4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page