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

Uploaded CPython 3.14Windows x86-64

frozen_cub-0.2.7-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (179.6 kB view details)

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

frozen_cub-0.2.7-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (174.1 kB view details)

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

frozen_cub-0.2.7-cp314-cp314-macosx_11_0_arm64.whl (50.8 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

frozen_cub-0.2.7-cp313-cp313-win_amd64.whl (15.3 kB view details)

Uploaded CPython 3.13Windows x86-64

frozen_cub-0.2.7-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (179.6 kB view details)

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

frozen_cub-0.2.7-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (174.6 kB view details)

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

frozen_cub-0.2.7-cp313-cp313-macosx_11_0_arm64.whl (50.6 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: frozen_cub-0.2.7-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 15.3 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.7-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 9d0df11553282e80c6f028cbf3efbd1b65ce724c35120ca4fb65dedddf514302
MD5 b51c877627c8d1b072e46403d60433d5
BLAKE2b-256 f0b66f78d56a81f8692e7eafce08d8594babded6acf934da92db979a8ca9e0e4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for frozen_cub-0.2.7-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d97023cb0c978da0a81d7894eb021e5ed81581af42c29656a45c1e5be7eb4418
MD5 abf56f897cf3dc8b97e672a23912e9ca
BLAKE2b-256 257847fb1dedfd4b4f67062d865a9031b0c6efca4c7e26167c128446daa5b16b

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.7-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.7-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for frozen_cub-0.2.7-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 605575873c40dfeb8356f4e0ea74fbfea6c292b912d4ca251008e1348035a027
MD5 220ea00623c57b221fdd26b144f78f36
BLAKE2b-256 cc0e6ffde76faaaed41102795f1e9ba4c3122f3ba227e220b249aa2138c2919e

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.7-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_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.7-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for frozen_cub-0.2.7-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 110a0af0df3fb22f2c320b56c1f9b7f5dddcd2c4d1a2a519f250f9972c3937f5
MD5 fc18a6d5a87a6180185d438c459f50a9
BLAKE2b-256 1346a4325c192393fb3eaac56d66d15c5a74e93ca3b02111efe8e19f7f294ae2

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: frozen_cub-0.2.7-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 15.3 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.7-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 4e0eac3e733fd4d04f590fb725bba41b5a99607977182fba1e2ec9204e9b6a03
MD5 6bc41ef0c374ac141595e61ff55acfc3
BLAKE2b-256 d573741708e7f25e5babf7dc1dede7b8deabdf98454f3a3b03d9a308db8d9078

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for frozen_cub-0.2.7-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 713da5c5bba55d4947a833fd7f115b546e9ddc9d36d694e5cb5ea953686b6862
MD5 a5bc9571d8ea619ac8c0d9372b0bfba4
BLAKE2b-256 908dbe341a14ac8b96965c2bf6269405de2a2b860eb499380eead0077741dc16

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.7-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.7-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for frozen_cub-0.2.7-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 bf6e6db0dda5a1ddfa730aa9252d5ba3a8250f564e0c7f1b5c98ad16691d6acd
MD5 449e0f12401d016587d5206a094b6c82
BLAKE2b-256 57a604474908661afd7d02904a708eb0fff50889d46a47896035f325791cbbe0

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.7-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_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.7-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for frozen_cub-0.2.7-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0dee7ecfe2d8b6aa542a3d897865f9f28121221cc26fd16a39fe36e9414b280d
MD5 dd5226530a5fc712291f2c8753f4cc1b
BLAKE2b-256 f262e33cd66502f7f0f5df15073fad6b19d593145279d3e776969e40f5b7c3fa

See more details on using hashes here.

Provenance

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