Skip to main content

Dependency Cache

🚧 Work In Progress 🚧

Description

Dependency Cache is a caching layer for object methods, with invalidation driven by a dependency graph. Rather than re-running expensive, deeply nested calculations on every call, it stores each method's result and only recomputes (and marks downstream methods for recalculation) when one of its declared dependencies actually changes. Under the hood, this project is written in Rust using pyo3 and built with maturin.

Installation

Install the latest stable version from PyPI:

pip install dependency-cache

API Overview

Export What it's for
DependencyCacheBase Base class to inherit from. Gives your instance a cache and a dependency graph.
dependency_cached(use_cache=True, dependencies=[...], track_runtime_dependencies=False, serialisable=False) A footgun-enabled decorator for a method where you explicitly declare all direct dependencies.
automagically_dependency_cached(use_cache=True, dependencies=[...], track_runtime_dependencies=True, serialisable=False) A decorator which automagically infers the direct dependencies. Optionally override the defaults and inference using the dependencies parameter.
plot_dependency_graph(obj, **kwargs) Visualizes an instance's dependency graph, for inspection/debugging.

Setup

This project uses (and requires) uv as a package manager and maturin to compile.

To set up a local dev environment:

  • install python dependencies
uv sync
  • generate local development file for testing (and update pyi file for accurate typechecking)
maturin develop --generate-stubs
maturin develop -r --generate-stubs
  • run python tests
uv run pytest
uv run pytest -vv
  • run rust tests
cargo test
  • temporary fix: generate stubs currently produces a file that is incorrectly formatted, use ruff to format the pyi file immediately
maturin develop --generate-stubs | uv run ruff format ./python/dependency_cache/dependency_cache.pyi

Quick Example

from dependency_cache import DependencyCacheBase, automagically_dependency_cached


class ExampleCalculation(DependencyCacheBase):
    """   C
        //  \\
       A      B
    """

    def __init__(self, x, y):
        super().__init__()
        self.x = x
        self.y = y

    @automagically_dependency_cached()
    def A(self):
        print("calculating A")
        return self.x

    @automagically_dependency_cached()
    def B(self):
        print("calculating B")
        return self.y

    @automagically_dependency_cached()
    def C(self):
        print("calculating C")
        return self.B() + self.A()


c = ExampleCalculation(3, 5)
print(c.C())  # calculates A, B, C -> 8
print(c.C())  # hits cache -> 8

c.update_cached_value("A", 0)  # invalidates C (but not B)
print(c.C())  # recalculates C -> 5

This example can be found here with more runnable examples and use cases provided in the python/examples folder.

uv run ./python/examples/example.py

TODOs

This project is still a work in progress, with everything from API to underlying design subject to change on my whim.

Current TODO list (in no particular order):

  • scenario analysis capability (add temporary cache to base)
  • add validation to static dependencies, ensure methods are of decorator class
  • improve plot_dependency_graph (maybe to GUI?) with moveable nodes
  • add object thread safety for python 3.14+
  • work out how best to handle nested objects

Release files for dependency_cache 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dependency_cache 0.2.2
File Size Uploaded
dependency_cache-0.2.2.tar.gz 156.8 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for dependency_cache 0.2.2
File
dependency_cache-0.2.2-cp38-abi3-win_amd64.whl CPython 3.8 abi3 Windows x86-64 Details
dependency_cache-0.2.2-cp38-abi3-win32.whl CPython 3.8 abi3 Windows x86-32 Details
dependency_cache-0.2.2-cp38-abi3-musllinux_1_2_x86_64.whl CPython 3.8 abi3 Linux musl 1.2+ x86-64 Details
dependency_cache-0.2.2-cp38-abi3-musllinux_1_2_i686.whl CPython 3.8 abi3 Linux musl 1.2+ x86-32 Details
dependency_cache-0.2.2-cp38-abi3-musllinux_1_2_armv7l.whl CPython 3.8 abi3 Linux musl 1.2+ ARMv7l Details
dependency_cache-0.2.2-cp38-abi3-musllinux_1_2_aarch64.whl CPython 3.8 abi3 Linux musl 1.2+ ARM64 Details
dependency_cache-0.2.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 abi3 Linux glibc 2.17+ x86-64 Details
dependency_cache-0.2.2-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl CPython 3.8 abi3 Linux glibc 2.17+ IBM System/390x Details
dependency_cache-0.2.2-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl CPython 3.8 abi3 Linux glibc 2.17+ PowerPC 64-le Details
dependency_cache-0.2.2-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl CPython 3.8 abi3 Linux glibc 2.17+ ARMv7l Details
dependency_cache-0.2.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.8 abi3 Linux glibc 2.17+ ARM64 Details
dependency_cache-0.2.2-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl CPython 3.8 abi3 Linux glibc 2.5+ x86-32 Details
dependency_cache-0.2.2-cp38-abi3-macosx_11_0_arm64.whl CPython 3.8 abi3 macOS 11.0+ ARM64 Details
dependency_cache-0.2.2-cp38-abi3-macosx_10_12_x86_64.whl CPython 3.8 abi3 macOS 10.12+ x86-64 Details

Total release size: 5.3 MB

Release files / dependency_cache-0.2.2.tar.gz

Download URL dependency_cache-0.2.2.tar.gz
Size 156.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0d010acc1580493cced37b5316fd0ba15e5219757b07dab52832ebca9b43ad2e
BLAKE2b-256 checksum
How to use checksums
ff8bd291a3961e5057bcdc1129235b4cc29b571a3616785e5267856fdda6b363
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / dependency_cache-0.2.2-cp38-abi3-win_amd64.whl

Download URL dependency_cache-0.2.2-cp38-abi3-win_amd64.whl
Size 200.1 kB
Tags CPython 3.8 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
dcdc07eb89d961ec3ac3867357fddb1d0441a34902b6cd634d0d0b040f7427b6
BLAKE2b-256 checksum
How to use checksums
04565255760dc12bd98eff91946e5c88af0f492974fdecaf6069b3d28772eecf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / dependency_cache-0.2.2-cp38-abi3-win32.whl

Download URL dependency_cache-0.2.2-cp38-abi3-win32.whl
Size 186.8 kB
Tags CPython 3.8 Windows x86-32 abi3
SHA-256 checksum
How to use checksums
4fa4b405dc16e315a903ecd32c0b47369f09dd62dc25c4a73f563cb24eef6fe5
BLAKE2b-256 checksum
How to use checksums
601fd6efbedc634490388d4e40180518559f61bf9b373822eed586baaa896226
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / dependency_cache-0.2.2-cp38-abi3-musllinux_1_2_x86_64.whl

Download URL dependency_cache-0.2.2-cp38-abi3-musllinux_1_2_x86_64.whl
Size 526.7 kB
Tags CPython 3.8 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
8eea00006c42200faf4d8e03a12312852d878e962c8a2933876f38df8d765b34
BLAKE2b-256 checksum
How to use checksums
2c39c8d68a1c16817a7952027a356aba14bc2a35cc279a971835a97386a6d048
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / dependency_cache-0.2.2-cp38-abi3-musllinux_1_2_i686.whl

Download URL dependency_cache-0.2.2-cp38-abi3-musllinux_1_2_i686.whl
Size 557.0 kB
Tags CPython 3.8 Linux musl 1.2+ x86-32 abi3
SHA-256 checksum
How to use checksums
8bbd116a824ec99bfb7272566851d7db9c2b7eaa4653377a95ad21388977fe08
BLAKE2b-256 checksum
How to use checksums
7da5da901f29989edf89714fe4d2cc6c06a099fe8dcac6c0b9e68e2db3187c1e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / dependency_cache-0.2.2-cp38-abi3-musllinux_1_2_armv7l.whl

Download URL dependency_cache-0.2.2-cp38-abi3-musllinux_1_2_armv7l.whl
Size 603.4 kB
Tags CPython 3.8 Linux musl 1.2+ ARMv7l abi3
SHA-256 checksum
How to use checksums
4cb3c39afaf532dfd372775381ee1401a239c8b87b6671f975f59a8c0e00168e
BLAKE2b-256 checksum
How to use checksums
a0136d0c3900e23d834adabb2806ab2aebf5eddf0c1020577fcb238573b83c0b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / dependency_cache-0.2.2-cp38-abi3-musllinux_1_2_aarch64.whl

Download URL dependency_cache-0.2.2-cp38-abi3-musllinux_1_2_aarch64.whl
Size 486.8 kB
Tags CPython 3.8 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
8212ceff5df6a2339ef616b0817f283c314151a1449dd89a4cb417beabfdfb2e
BLAKE2b-256 checksum
How to use checksums
128b411c1c1350a6a6a524c7ffc982761a24358fcc2b4d9b775035be9eeacb5e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / dependency_cache-0.2.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL dependency_cache-0.2.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 314.3 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
0c31c9ce3d47d7c1989efccddfd93c17f63b9484d509eba68d21484890310dc7
BLAKE2b-256 checksum
How to use checksums
d01e659fd969a5db3c6c50fada54a66ef1122377b195965b51ad52e395c6dffd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / dependency_cache-0.2.2-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl

Download URL dependency_cache-0.2.2-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Size 347.7 kB
Tags CPython 3.8 Linux glibc 2.17+ IBM System/390x abi3
SHA-256 checksum
How to use checksums
ccef1029cbfb0a9989b42ee6dd4b73ad2c48884f8c3c1313773b710f32b979ec
BLAKE2b-256 checksum
How to use checksums
901b4332ba6552fd79f6bcd3511eac463cad3901aa0ea19c2040211242368240
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / dependency_cache-0.2.2-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl

Download URL dependency_cache-0.2.2-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Size 345.3 kB
Tags CPython 3.8 Linux glibc 2.17+ PowerPC 64-le abi3
SHA-256 checksum
How to use checksums
d9b1f4666e80476a2269f07e3a053ebe1880c092063b8c8a42dd0e3713dab914
BLAKE2b-256 checksum
How to use checksums
825052a53f75bb54ad9f476a282a237d41856647b8f8bf33619444c19e739a99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / dependency_cache-0.2.2-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl

Download URL dependency_cache-0.2.2-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Size 326.3 kB
Tags CPython 3.8 Linux glibc 2.17+ ARMv7l abi3
SHA-256 checksum
How to use checksums
118d62a2558c911fb50603222c3adabe7519ea69aae9bd1ce2d3c29a3e8f1ee4
BLAKE2b-256 checksum
How to use checksums
191dc412bdcfd9e4563f9329b00c1979977097d202e1c35725a1f5c3b2469ee9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / dependency_cache-0.2.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL dependency_cache-0.2.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 307.7 kB
Tags CPython 3.8 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
6cd4169eab642a237b12391feab488aa263c888995011878f5d7b39754338706
BLAKE2b-256 checksum
How to use checksums
27527c9f7ccb3694476ded4864c18bb95df19b4eec88c5dc6877945fe3c55321
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / dependency_cache-0.2.2-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl

Download URL dependency_cache-0.2.2-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl
Size 338.8 kB
Tags CPython 3.8 Linux glibc 2.5+ x86-32 abi3
SHA-256 checksum
How to use checksums
c2221c4ff3816f03acfea49fb9a97ec0fa41f8449bbea311278ca1ce4bd31eb0
BLAKE2b-256 checksum
How to use checksums
1f30539067ed0787fa68659c489d3907d0f6c726b4fecd657e65e8506635e9fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / dependency_cache-0.2.2-cp38-abi3-macosx_11_0_arm64.whl

Download URL dependency_cache-0.2.2-cp38-abi3-macosx_11_0_arm64.whl
Size 284.9 kB
Tags CPython 3.8 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
8d58e255cd5459c3c59d9a6a733b3c8b28e50fa0084ef2b745abfa655a3c40ac
BLAKE2b-256 checksum
How to use checksums
a5142db1cdc8aab58fa458341c5776e62e9739652c942b2c88e36d76d7d71bdd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / dependency_cache-0.2.2-cp38-abi3-macosx_10_12_x86_64.whl

Download URL dependency_cache-0.2.2-cp38-abi3-macosx_10_12_x86_64.whl
Size 294.4 kB
Tags CPython 3.8 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
d6a6b8c92096da2c09c3446902126785baec825cfb5588ffcd7125a6686d2401
BLAKE2b-256 checksum
How to use checksums
05afae5a7f6002b4946b698f59263a0b5ef3b9ce7e0fce71b8111586fa313bb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release history Release notifications | RSS feed

0.4.1

31 release files

0.4.0

31 release files

0.3.0

31 release files

0.2.4

31 release files

0.2.3

31 release files

This release

0.2.2 This release

15 release files

0.1.3

15 release files

0.1.2

15 release files

0.1.1

15 release files

0.1.0

15 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