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.12-cp314-cp314-win_amd64.whl (15.7 kB view details)

Uploaded CPython 3.14Windows x86-64

frozen_cub-0.2.12-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (197.7 kB view details)

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

frozen_cub-0.2.12-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (205.6 kB view details)

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

frozen_cub-0.2.12-cp314-cp314-macosx_11_0_arm64.whl (54.4 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

frozen_cub-0.2.12-cp313-cp313-win_amd64.whl (15.7 kB view details)

Uploaded CPython 3.13Windows x86-64

frozen_cub-0.2.12-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (198.5 kB view details)

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

frozen_cub-0.2.12-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (205.4 kB view details)

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

frozen_cub-0.2.12-cp313-cp313-macosx_11_0_arm64.whl (54.3 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for frozen_cub-0.2.12-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 43194fb740a0574b685f688d5d3ed7db721bb6e2aaf834a2d7b80ba9636851e2
MD5 17dfdb5c7fb8ec857b865cf05adbf007
BLAKE2b-256 dad970580d1960fafc329d6207201167c8c9d72e90289341786c431f95c832f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.12-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.12-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.12-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c259577fa31e97839ebe5c238679198f1b973ff9ec785ac978e56b32fec859bf
MD5 b0b9a0cf957c53c7431b38057ab46707
BLAKE2b-256 d25565bf85485e9b8785e40af98104ab16fbacf8fa73a3dd252e22f260cda878

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.12-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.12-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for frozen_cub-0.2.12-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 530ed70290395c7c9842c203d595652625b2fd976194c8726a97f68164842797
MD5 8f3ae3a98a892dbb2517008fac064cc7
BLAKE2b-256 4a75ed1d83e9bb4d60135eda773006ad1a3a0cdaa20acefe375baf378e1f9a3b

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.12-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.12-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for frozen_cub-0.2.12-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 680d0547317551b2743ef83748a25cde9ec1f9cc9bf7a9a8886e39af3aa7305f
MD5 8f8c922830a712540f3135e64baf6957
BLAKE2b-256 33291eefb7aa890c0c9dd9dd5b3c143e600ced782100799d6085fddb509db828

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.12-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.12-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for frozen_cub-0.2.12-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c19131718271b3d5738898150a0a5aa8da822caa0f9f61af9c00f64995a42489
MD5 89efd88bc4c5ed1c44639949c061eae7
BLAKE2b-256 4e0f9805ea57c0ab0a31ae5992dfb661eebd50a0a19ab1803355c7d271c69dde

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.12-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.12-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.12-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 890901ebc038d6ac6d64ed9b14c8856874bbfd0c08dca0b371e0ac256b2a3e9c
MD5 37fdce9b957f8a4942fd5f4f1048afae
BLAKE2b-256 159c4c4679d9fec0d686fb548c1186f280a35e349e10e9bab2b40888ecacc288

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.12-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.12-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for frozen_cub-0.2.12-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b2f788ca306cd9b52ca47684697ca4a6b2296b204e8fec58ed1fd841cc98bbdf
MD5 eac3246420e1a13d400adb724788aa5e
BLAKE2b-256 2243f05c59326614909a4479da9cdce9175b555ee6b0c77c691e8d2cab78937c

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.12-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.12-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for frozen_cub-0.2.12-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4f7ab5cb4713f7a46496344cbbff78cceffe92df1c38724f047113583c52bbc0
MD5 b8b2ba9042079a9c83981a14084334d4
BLAKE2b-256 a20f97853fe4ecd182085222fac79ae096439d12a7fea60ad2a567c3207bae45

See more details on using hashes here.

Provenance

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