Skip to main content

Summary

df-diskcache is a Python library for caching pandas.DataFrame objects to local disk.

PyPI package version Supported Python versions CI status of Linux/macOS/Windows Test coverage: coveralls CodeQL

Installation

pip install df-diskcache

Features

Supports the following methods:

  • get: Get a cache entry (pandas.DataFrame) for the key. Returns None if the key is not found.

  • set: Create a cache entry with an optional time-to-live (TTL) for the key-value pair.

  • update

  • touch: Update the last accessed time of a cache entry to extend the TTL.

  • delete

  • prune: Delete expired cache entries.

  • Dictionary-like operations:
    • __getitem__

    • __setitem__

    • __contains__

    • __delitem__

Usage

Basic Usage

import pandas as pd
from dfdiskcache import DataFrameDiskCache

cache = DataFrameDiskCache()
url = "https://raw.githubusercontent.com/pandas-dev/pandas/v2.1.3/pandas/tests/io/data/csv/iris.csv"

df = cache.get(url)
if df is None:
    print("cache miss")
    df = pd.read_csv(url)
    cache.set(url, df)
else:
    print("cache hit")

print(df)

You can also use operations like a dictionary:

import pandas as pd
from dfdiskcache import DataFrameDiskCache

cache = DataFrameDiskCache()
url = "https://raw.githubusercontent.com/pandas-dev/pandas/v2.1.3/pandas/tests/io/data/csv/iris.csv"

df = cache[url]
if df is None:
    print("cache miss")
    df = pd.read_csv(url)
    cache[url] = df
else:
    print("cache hit")

print(df)

Cache existence check

You can check if a cache entry exists by using the in operator.

import pandas as pd
from dfdiskcache import DataFrameDiskCache

cache = DataFrameDiskCache()
url = "https://raw.githubusercontent.com/pandas-dev/pandas/v2.1.3/pandas/tests/io/data/csv/iris.csv"

if url in cache:
    print("cache exists")
    df = cache[url]
else:
    print("cache does not exist")

Set TTL for cache entries

You can set the default TTL for cache entries by setting the DataFrameDiskCache.DEFAULT_TTL or the ttl parameter of the set method.

import pandas as pd
from dfdiskcache import DataFrameDiskCache

DataFrameDiskCache.DEFAULT_TTL = 10  # you can override the default TTL (default: 3600 seconds)

cache = DataFrameDiskCache()
url = "https://raw.githubusercontent.com/pandas-dev/pandas/v2.1.3/pandas/tests/io/data/csv/iris.csv"

df = cache.get(url)
if df is None:
    df = pd.read_csv(url)
    cache.set(url, df, ttl=60)  # you can set a TTL for the key-value pair

print(df)

Delete cache entries

You can delete a cache entry by using the del operator or the delete method.

import pandas as pd
from dfdiskcache import DataFrameDiskCache

cache = DataFrameDiskCache()

key = "example key"
if key not in cache:
    df = pd.DataFrame([["a", 1], ["b", 2]], columns=["col_a", "col_b"])
    cache.set(key, df)

# delete a cache entry by using del operator
del cache[url]

# delete a cache entry by using delete method
cache.delete(url)

Cache lifetime management

Expired cache entries are automatically deleted when you access a cache entry or invoke the prune method.

You can refresh the last accessed time of a cache entry by using the touch method.

Dependencies

Metadata

Release files for df-diskcache 0.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 df-diskcache 0.1.0
File Size Uploaded
df_diskcache-0.1.0.tar.gz 12.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for df-diskcache 0.1.0
File Interpreter ABI Platform
df_diskcache-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.5 kB

Release files / df_diskcache-0.1.0.tar.gz

Download URL df_diskcache-0.1.0.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
29f33692deddc2b8ef348004e7131955cda1f792ff4c94bc9b1315ddaad5ac58
BLAKE2b-256 checksum
How to use checksums
53f436ef9f75c08c0b150f8741c6ac9aee486d32851c6e950c7fe079950a43b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2025.

Transparency log

Release files / df_diskcache-0.1.0-py3-none-any.whl

Download URL df_diskcache-0.1.0-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7ee2fe8a3c1e5515871dc98095ffc0d93d7eba43b9d08941f3f0b56c04a2d19d
BLAKE2b-256 checksum
How to use checksums
9d8603b18b7a091d57b8acc2a089e8732d0ea3f903087f5ee21d7d37c51fbbd7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

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