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

Uploaded CPython 3.14Windows x86-64

frozen_cub-0.1.12-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

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

frozen_cub-0.1.12-cp314-cp314-macosx_11_0_arm64.whl (238.1 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

frozen_cub-0.1.12-cp313-cp313-win_amd64.whl (40.7 kB view details)

Uploaded CPython 3.13Windows x86-64

frozen_cub-0.1.12-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

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

frozen_cub-0.1.12-cp313-cp313-macosx_11_0_arm64.whl (236.1 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

frozen_cub-0.1.12-cp312-cp312-win_amd64.whl (40.7 kB view details)

Uploaded CPython 3.12Windows x86-64

frozen_cub-0.1.12-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

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

frozen_cub-0.1.12-cp312-cp312-macosx_11_0_arm64.whl (239.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for frozen_cub-0.1.12-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 9ca2256aaff8fc671e4f8a0169652f4d98f3bb99d2ee745200e253d8c41f2a94
MD5 0683e8ab76b5d7aaca350baf7728a1a7
BLAKE2b-256 75cb03ca37bac45f49630f286990b8e7de88de8bbd5570fb2ec4987c00078b13

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.1.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.1.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.1.12-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0363de19d37afb2dd2c1de13d1869752e01cb9196d1f2c2e333a2ba76e5ad7d6
MD5 cbf0dd9bbf16688fa5204f54c1bdae06
BLAKE2b-256 52294ad96269ce71a70f60b6ac2c3e1e6641a358acde472d0e967c4cc9969e84

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for frozen_cub-0.1.12-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 142b9e5cbfe9732174a2fdcf535027d4c3aad12b84a53a146b1c3ffd600a3279
MD5 d5d939ef7543bee0895c22470b47b15b
BLAKE2b-256 cb1f687e164f217c4185f41c2846b9dfe604b6359116b0652ee6ce7bfd6b8c4f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for frozen_cub-0.1.12-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c53afba8516ede47dc2a80db6b49fcd8c5d77202296ab874c4b0ca777ea2f342
MD5 1a1e07977e024b0049ad30165c628d37
BLAKE2b-256 e65bf8f8c69efc598022215d2345cec9aba3a08aca6156534872ee53678003c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.1.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.1.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.1.12-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2ff4ca9959ec57839e91a48b2a4ea31a1cbbdd653697aab0236ee840a9a7f4d2
MD5 18d6dc16575743b67dac1c6b822ab462
BLAKE2b-256 4aa870a3b69ab3bf38bb54cb90fc9b092409c405d6e3c65494923fce8cf2ab51

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for frozen_cub-0.1.12-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ead4802ae9e9c9676fd6c74e59dce58ad5271a041bec4e8e956a7439ef983901
MD5 9fb74f2e770e6fe0428bc5b85de90564
BLAKE2b-256 f710d501c0e570230fc3f2942ba5c5d5e15921ac82bbe31512249008f16a6a4a

See more details on using hashes here.

Provenance

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

File details

Details for the file frozen_cub-0.1.12-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for frozen_cub-0.1.12-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 97a5ac92062ca98697d12547eae6ce297d1b6ffbf87353be705cea003f862f25
MD5 7840bbe6c1c8edee1b0ae32023e76851
BLAKE2b-256 2ad8a9b514c487a989a43a560bc28a3703e64de2e10dc464f5bee3831f78368d

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.1.12-cp312-cp312-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.1.12-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for frozen_cub-0.1.12-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c2e37c371c44c81650ebca6baa3b4179cb073571e574eef6b755bc8f0e3aad15
MD5 e71c8c43c11ed8f78d3feb2edee235b2
BLAKE2b-256 bb01c53c9e2cb93a06ceb729aa0d58722c64a1463b05f513073ab52d9b85b766

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.1.12-cp312-cp312-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.1.12-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for frozen_cub-0.1.12-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b37784a1e2c2120fa5b0668f6f43185986e0ecaf0a8fffa63ea755fdbc3a3841
MD5 80a8b6a87c55d843e11dfb941349359a
BLAKE2b-256 beb7674fac4a53abcd157859c1ea1e21bbb190450400760aee05daff3298e3a7

See more details on using hashes here.

Provenance

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