Pickling and unpickling of function arguments
Project description
sylte
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sylte-0.0.3.tar.gz.
File metadata
- Download URL: sylte-0.0.3.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-1027-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cddef9f73c3383f71aa89754452b43781c2d92844c045964ea3b2bb14325e2a4
|
|
| MD5 |
3102c0e152216b6473c0b54d9e9750ea
|
|
| BLAKE2b-256 |
8eb8e60821826fe75480397bdb9be771df69a5eb6be2fbf1748e50d7d5709bdf
|
File details
Details for the file sylte-0.0.3-py3-none-any.whl.
File metadata
- Download URL: sylte-0.0.3-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.10.0 Linux/5.11.0-1027-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb0c5ebcda3aa105d7ea6e51c7c598b473aba227d779a80a3322b1eb64020e26
|
|
| MD5 |
93ff585173c4ef650269414ef9863d1a
|
|
| BLAKE2b-256 |
f412203f8abcfe5f57ca4822179139195ee2b58befca9a831358e510498e502e
|