Skip to main content

cache results of slow function to disk

Project description

pyfilecache

cache results of slow function to disk

Install

pip install pyfilecache

Examples

Basic Usage

# examples/add.py
from pyfilecache import file_cache

@file_cache
def add(a, b):
    print(f'adding {repr(a)} and {repr(b)}')
    return a + b

print(repr(add(1, 2)))
print(repr(add(1, 2)))
print(repr(add('1', '2')))
print(repr(add('1', '2')))
$ python3 examples/add.py
adding 1 and 2
3
3
adding '1' and '2'
'12'
'12'
$ python3 examples/add.py
3
3
'12'
'12'

Customized Reader and Writer

# examples/df.py
import pandas as pd
from functools import partial
from pyfilecache import file_cache

@file_cache(
    reader=partial(pd.read_csv, index_col=0),
    writer=pd.DataFrame.to_csv
)
def func(a, b):
    print("func called with args", a, b)
    return pd.DataFrame(
        data = {
            'col1': [1, 2],
            'col2': [a, b]
        }
    )

print(func(3, 4))
print(func(3, 4))
$ python3 examples/df.py 
func called with args 3 4
   col1  col2
0     1     3
1     2     4
   col1  col2
0     1     3
1     2     4
$ python3 examples/df.py 
   col1  col2
0     1     3
1     2     4
   col1  col2
0     1     3
1     2     4

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

pyfilecache-0.1.3-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

Details for the file pyfilecache-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: pyfilecache-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 3.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.8.10

File hashes

Hashes for pyfilecache-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d58a22f4865f9e8badff03570af780bc2539908c1f1e5fd45cac47d6d8ab4521
MD5 346af57d0b4dbf1d947a0c274427d2ee
BLAKE2b-256 6542825ed554912e8cfa2ca2fe3a42a0e1481c3811f947befff28c0d10d7e6f4

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