Skip to main content

A set of C and Python implementations of immutable, hashable, and performant frozen objects.

Project description

Frozen Cub

pypi version

A high-performance library for immutable, hashable data structures in Python. Built with Cython for speed.

Supports Python 3.12, 3.13, and 3.14

Features

  • FrozenDict: An immutable dictionary that can be used as a dict key or in sets
  • freeze(): Recursively freeze nested data structures (dicts, lists, tuples, sets)
  • LRUCache: A fast LRU cache with O(1) operations
  • CacheKey: A lightweight hashable key for caching based on two values

Installation

pip install frozen-cub

With uv:

uv add frozen-cub

Quick Start

Freezing Data Structures

from frozen_cub.frozen import freeze, FrozenDict

# Freeze a nested dictionary
data = {
    "user": "bear",
    "settings": {"theme": "dark", "notifications": True},
    "tags": ["python", "cython"],
}
frozen = freeze(data)

# Now it's hashable - use as dict key or in sets
cache = {frozen: "some_result"}
unique_configs = {frozen}

FrozenDict

from frozen_cub.frozen import FrozenDict

# Create directly from items
fd = FrozenDict([("a", 1), ("b", 2)])

# Or from a dict
fd = FrozenDict({"a": 1, "b": 2})

# Access like a regular dict
print(fd["a"])  # 1
print(fd.get("c", "default"))  # "default"
print(list(fd.keys()))  # ["a", "b"]

# Use as a dict key (it's hashable!)
lookup = {fd: "found it"}

LRU Cache

from frozen_cub.lru_cache import LRUCache

# Create a cache with max 100 items
cache: LRUCache[str, dict] = LRUCache(capacity=100)

# Basic operations
cache["key"] = {"data": "value"}
result = cache.get("key")  # Returns {"data": "value"}
result = cache.get("missing", "default")  # Returns "default"

# Dict-like interface
"key" in cache  # True
del cache["key"]
len(cache)  # 0

CacheKey

from frozen_cub.utils import CacheKey

# Create a hashable key from two values
key = CacheKey(int, 42)

# Use as dict key or in sets
cache = {key: "cached_value"}

# For more than two values, use tuples
key = CacheKey("my_cache", (arg1, arg2, arg3))

Cython API

For maximum performance in other Cython code, you can use the inlined C functions directly:

from frozen_cub.frozen cimport inline_freeze, FrozenDict

# inline_freeze is inlined at compile time - zero function call overhead
cdef object frozen = inline_freeze(my_dict)

API Reference

freeze(obj)

Recursively converts mutable objects to immutable equivalents:

Input Type Output Type
dict FrozenDict
list tuple
set frozenset

FrozenDict

An immutable, hashable dictionary.

Methods:

  • get(key, default=None) - Get value with optional default
  • keys() - Return list of keys
  • values() - Return list of values
  • items() - Return list of (key, value) tuples
  • __getitem__(key) - Get value, raises KeyError if missing
  • __contains__(key) - Check if key exists
  • __hash__() - Returns cached hash value
  • __len__() - Return number of items

LRUCache[K, V]

A generic LRU cache with configurable capacity.

Constructor:

  • LRUCache(capacity=512) - Create cache with max capacity

Methods:

  • get(key, default=None) - Get value with optional default
  • set(key, value) - Set value (alias for __setitem__)
  • pop(key, default=None) - Remove and return value
  • clear() - Remove all items
  • __getitem__(key) - Get value, raises KeyError if missing
  • __setitem__(key, value) - Set value
  • __delitem__(key) - Delete key, raises KeyError if missing
  • __contains__(key) - Check if key exists
  • __len__() - Return number of items

CacheKey

A lightweight, hashable key for caching based on two values.

Constructor:

  • CacheKey(value1, value2) - Create a cache key from two hashable values

Methods:

  • __hash__() - Returns cached hash value
  • __eq__(other) - Compare equality with another CacheKey

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 Distributions

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

frozen_cub-0.2.9-cp314-cp314-win_amd64.whl (15.6 kB view details)

Uploaded CPython 3.14Windows x86-64

frozen_cub-0.2.9-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (197.0 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

frozen_cub-0.2.9-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (204.4 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

frozen_cub-0.2.9-cp314-cp314-macosx_11_0_arm64.whl (54.8 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

frozen_cub-0.2.9-cp313-cp313-win_amd64.whl (15.6 kB view details)

Uploaded CPython 3.13Windows x86-64

frozen_cub-0.2.9-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (197.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

frozen_cub-0.2.9-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (204.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

frozen_cub-0.2.9-cp313-cp313-macosx_11_0_arm64.whl (54.7 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

Details for the file frozen_cub-0.2.9-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: frozen_cub-0.2.9-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for frozen_cub-0.2.9-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 d58c8a3fbf3512d9e32e98c3a839360227c3e563997957f9a0c8126bf6419044
MD5 f74b5ecc17a1728a625fd17b57a74a11
BLAKE2b-256 91b01970381af0a3f60f11852c5ac09a09403f611680293c3a024d7f59516371

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.9-cp314-cp314-win_amd64.whl:

Publisher: build-wheels.yml on sicksubroutine/frozen-cub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file frozen_cub-0.2.9-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for frozen_cub-0.2.9-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 815ec7dc4e00e65d65e5b435e891bce7263fbd02416bf2a43de2a645bab927be
MD5 b0ccb84ea7f5d6808dc831014d32821a
BLAKE2b-256 195f4e8443cf48faaf3b200c924a101cba12844390455bf2741d1cf743dfa295

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.9-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build-wheels.yml on sicksubroutine/frozen-cub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file frozen_cub-0.2.9-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for frozen_cub-0.2.9-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e0e1fa2cf45a4253e46f15066f073375aef5e2d71715e510684303cee0ad2aea
MD5 4ccbe6013101af662ed0d0d76d7a232c
BLAKE2b-256 4dc394e989aaad35a9a93bd54100819232468c8ef3beb13effad62642ee9be65

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.9-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl:

Publisher: build-wheels.yml on sicksubroutine/frozen-cub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file frozen_cub-0.2.9-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for frozen_cub-0.2.9-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 90c795c5c35c32b2c43ac7fbdbb62086b6f60317b2311243de24c61fc846d290
MD5 ad61c1bb783d117374ed9253604b4d29
BLAKE2b-256 ae75661c6567e8bced654c850b3b0be0d7ecbedd2f0ada5150b34b8b99a16451

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.9-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on sicksubroutine/frozen-cub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file frozen_cub-0.2.9-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: frozen_cub-0.2.9-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for frozen_cub-0.2.9-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 6ebf3395dd3686842e0dd94cc2aca3cf8d428bb2f781a1d3dff507afe3142498
MD5 ac0bbc2c8cb5658f65ec07bc26ce4abf
BLAKE2b-256 440ba73301efc18f30259c7d7bacdf8b464d435fac422b4928b379004f91aca6

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.9-cp313-cp313-win_amd64.whl:

Publisher: build-wheels.yml on sicksubroutine/frozen-cub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file frozen_cub-0.2.9-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for frozen_cub-0.2.9-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7f9d37a356b69c93a71cc28a68d69564b34e63b94d541a5159bcdfbbb4d0f6cc
MD5 58489109d7e482cec33e2db7a4deae1d
BLAKE2b-256 503fab5556127fda0467344b9c0f9f806425e231612842a47fdab8e76f526c56

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.9-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build-wheels.yml on sicksubroutine/frozen-cub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file frozen_cub-0.2.9-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for frozen_cub-0.2.9-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 da8af86ac0533093a7553d632deed2ca8234664a5b6d7e6dcab5f3cd36c4e561
MD5 061755bc1b4b6716800847ebfce63770
BLAKE2b-256 b89eace5710a96b5c39882a945d8dfdc3ba15efe04d18840ca493c0642fea90f

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.9-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl:

Publisher: build-wheels.yml on sicksubroutine/frozen-cub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file frozen_cub-0.2.9-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for frozen_cub-0.2.9-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 33fb64e3b95f7a7f2100c756bae2d0ac5613a2f2eaf0455c7dcf4cdc8dc24228
MD5 1664bac8126485b0dbac3bf865e08fdf
BLAKE2b-256 f29b704a258a994ace7816f2e96425ccdfd2d85578cc8a7970e0a648a7a35d48

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.9-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on sicksubroutine/frozen-cub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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