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.1

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.1
File Size Uploaded
dependency_cache-0.2.1.tar.gz 156.4 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for dependency_cache 0.2.1
File
dependency_cache-0.2.1-cp38-abi3-win_amd64.whl CPython 3.8 abi3 Windows x86-64 Details
dependency_cache-0.2.1-cp38-abi3-win32.whl CPython 3.8 abi3 Windows x86-32 Details
dependency_cache-0.2.1-cp38-abi3-musllinux_1_2_x86_64.whl CPython 3.8 abi3 Linux musl 1.2+ x86-64 Details
dependency_cache-0.2.1-cp38-abi3-musllinux_1_2_i686.whl CPython 3.8 abi3 Linux musl 1.2+ x86-32 Details
dependency_cache-0.2.1-cp38-abi3-musllinux_1_2_armv7l.whl CPython 3.8 abi3 Linux musl 1.2+ ARMv7l Details
dependency_cache-0.2.1-cp38-abi3-musllinux_1_2_aarch64.whl CPython 3.8 abi3 Linux musl 1.2+ ARM64 Details
dependency_cache-0.2.1-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.1-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.1-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.1-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl CPython 3.8 abi3 Linux glibc 2.17+ ARMv7l Details
dependency_cache-0.2.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.8 abi3 Linux glibc 2.17+ ARM64 Details
dependency_cache-0.2.1-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl CPython 3.8 abi3 Linux glibc 2.5+ x86-32 Details
dependency_cache-0.2.1-cp38-abi3-macosx_11_0_arm64.whl CPython 3.8 abi3 macOS 11.0+ ARM64 Details
dependency_cache-0.2.1-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.1.tar.gz

Download URL dependency_cache-0.2.1.tar.gz
Size 156.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ffab4d1d3ac28cfae3ca3741156d59171a4a3957b67d961be285101b969f5ec0
BLAKE2b-256 checksum
How to use checksums
c7a751b1411e5216ace88bbb873893c6dce90fa472bd81347b4946a7c13c67ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

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

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

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

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

Download URL dependency_cache-0.2.1-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
9f549101e644dab038e09d8a88a11beedd880e02c0b25cedac1e3aeddeff4e6a
BLAKE2b-256 checksum
How to use checksums
1893f195cba0e927a7e6f4d3a4ba276e120abc1a7bdadc85be1fb88b930fdc33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

Download URL dependency_cache-0.2.1-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
09b07b1516eecc25440e9d781ca9e69cc7ea654fc2cb05c3eeae52431cd57ab5
BLAKE2b-256 checksum
How to use checksums
d6d779cd979a78744e0d83b9d43a2d48864dd082c2c888a0667baae99f05e56c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

Download URL dependency_cache-0.2.1-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
ae30c58845405c71d8af6d4f78257c5891f94275c846b7325e347a8e89ba4334
BLAKE2b-256 checksum
How to use checksums
25ac98b0853f9b18ea9aaf945bc9755795e6c7ca68e5afccea0d15ff4f4295ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

Download URL dependency_cache-0.2.1-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
0837a2a305b6bde0037aa60b4238ba205a64534082b78247f493874a03dafddf
BLAKE2b-256 checksum
How to use checksums
95687bc54cb7614965522651130a31d27f49989f35cc7672c0938791a51ecaf3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

Download URL dependency_cache-0.2.1-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
0357441700c55c4db76474b5d7d8284bc98a8a26e968b3aa2617478948b1bf77
BLAKE2b-256 checksum
How to use checksums
f77b0b15f1d1613534d2973dfa45a60ecf248649c67dfebb8503116044a48273
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

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

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

Download URL dependency_cache-0.2.1-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
9409a0dc79540efdb326415c18e4e97922a4fbbfdd62834d1a392ddf02daf65e
BLAKE2b-256 checksum
How to use checksums
3fca9555945a129ba4cec3f1dd210aa03d9039468e4f644c2bc8e02bc8cd50c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

Download URL dependency_cache-0.2.1-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
24181c880b486903d2e11f406d475dad9dab624102e3496b0bcc4e7f47041945
BLAKE2b-256 checksum
How to use checksums
c72a7cb86f50e34b9f4675f25dbb551ad6f06b2ba9eb754501572e1557d9a5cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

Download URL dependency_cache-0.2.1-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
1517cd260317b5af7fe41b55b8a6dae225c14b3d732b6c64cbdf8a305c02e5f0
BLAKE2b-256 checksum
How to use checksums
0f34b1a0e6eb563f67ae5b193f48a4f282983040b42d3625ea299c30f52645af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

Download URL dependency_cache-0.2.1-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
0b200a0190c440d90fff9095586be108e10c983bac785eac80238dae3e1afa68
BLAKE2b-256 checksum
How to use checksums
f12f49918eadef2fce9afd5f870f7efad17516c07089be0940a1ec4c286aaa67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

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

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

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

Download URL dependency_cache-0.2.1-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
92719b6c85993d9c19d12285726ef1bda4022b3acb7d05e39c7cdfc2b0f026d5
BLAKE2b-256 checksum
How to use checksums
6c1f966a197ecfa4cb8402db79225297825eb355f96c1e471a5fa3b7a2384c8f
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

0.2.2

15 release files

This release

0.2.1 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