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.21-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (260.6 kB view details)

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

frozen_cub-0.2.21-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (269.0 kB view details)

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

frozen_cub-0.2.21-cp314-cp314-macosx_15_0_arm64.whl (58.9 kB view details)

Uploaded CPython 3.14macOS 15.0+ ARM64

frozen_cub-0.2.21-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (261.3 kB view details)

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

frozen_cub-0.2.21-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (268.8 kB view details)

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

frozen_cub-0.2.21-cp313-cp313-macosx_15_0_arm64.whl (58.8 kB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

frozen_cub-0.2.21-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (260.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

frozen_cub-0.2.21-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (268.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

frozen_cub-0.2.21-cp312-cp312-macosx_15_0_arm64.whl (58.8 kB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

File details

Details for the file frozen_cub-0.2.21-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for frozen_cub-0.2.21-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1b429975b4ae29dbcc7f5cb6b00d28152e40784b30b2de2747a400218ae374cd
MD5 baa63498152fe3ebab4cc1e43ff443a7
BLAKE2b-256 8647a1ef669cc6de52e6f405b09183cf89ff2d6bc735dc109c4169bb3f8995e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.21-cp314-cp314-manylinux_2_24_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.21-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for frozen_cub-0.2.21-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 12bf941008b4a96a8dcb536e4dfff90e6516254a347a98c3255da779b02f0ef8
MD5 d05bfce851cc6c0a5649470005a359a6
BLAKE2b-256 873fccd52ca1255e3c5e805482a7297c75a8c513d46cb2d7440995fb4578f0e2

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.21-cp314-cp314-manylinux_2_24_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.21-cp314-cp314-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for frozen_cub-0.2.21-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 cd1a58bd46854fc44bd9ca7a5a62cb5a19f879f11fd77d5e5f5bc0cc1ae99eba
MD5 f51b1e6c3901ec6a659e4b6bfee18058
BLAKE2b-256 ca503f482a56ad21ca91f2972df0c36e2a20bf223079a67d0b008d35703f17a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.21-cp314-cp314-macosx_15_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.21-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for frozen_cub-0.2.21-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b4e5aa9fcd17d6981697e2b1bd1e473924f67c805bf7da99ac3d43536df9a42d
MD5 f55f23bdfd4b33fe5a07e407f1c5fcef
BLAKE2b-256 812388e0d4eba8ae882ba49fe0fd088211ca2c54b4cd76027b50c22e05f95a65

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.21-cp313-cp313-manylinux_2_24_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.21-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for frozen_cub-0.2.21-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 45c430fcd813714ca8e671f87026f85d0b2bef8ebb0dbcbbb04d2bf8feb26025
MD5 1ed41b71b17a27906ce4ddee75f7d290
BLAKE2b-256 b713b9b3b97869b1fe49e08858de3547aba2f66caf98162ddb524ff29f8aa1f9

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.21-cp313-cp313-manylinux_2_24_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.21-cp313-cp313-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for frozen_cub-0.2.21-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 52b5a7eff480bb68943d8f25877bb0e6ff77a37bee5ff3f751a4222f469f9b2a
MD5 df412949c4b98be3ee4ef08e4d2c05a8
BLAKE2b-256 083b938f4615e54f55ce28f53b99a7c01f5838bbdb7452f3054a2816a7918516

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.21-cp313-cp313-macosx_15_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.21-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for frozen_cub-0.2.21-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6b769c4343a9bf54e47de436d71dbade5556883a481564a3d450aee0d72fa85d
MD5 5934e285161afd4b5b45049c7c536d7f
BLAKE2b-256 271a978e62fe88f02e973ed4c5ae6a6799e285aa1f5c0af556e669c41b0e3c33

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.21-cp312-cp312-manylinux_2_24_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.21-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for frozen_cub-0.2.21-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a3a8f0eabe479d8b117480995821f314278de3fbfefd29c52cfd4219b3492cb6
MD5 750e14a1cb97a549cc619dd920333cbb
BLAKE2b-256 cd2c0df10019541ca4fb681a861b5fb241e0357231a991060459fa34746fe078

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.21-cp312-cp312-manylinux_2_24_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.21-cp312-cp312-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for frozen_cub-0.2.21-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 a3ba6e0188707537ff2c436d5bbf93067f3b300bfd6e9e54f446ebbdd782a856
MD5 3524a226364ed7e2d2c7691e3b9d97fb
BLAKE2b-256 550d0e0af5d51265236d762f73e14049c16068bf58fa37fca1dd9ec56e2b2624

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.21-cp312-cp312-macosx_15_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