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

Uploaded CPython 3.14Windows x86-64

frozen_cub-0.2.10-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (199.2 kB view details)

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

frozen_cub-0.2.10-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (206.8 kB view details)

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

frozen_cub-0.2.10-cp314-cp314-macosx_11_0_arm64.whl (55.3 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

frozen_cub-0.2.10-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (199.9 kB view details)

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

frozen_cub-0.2.10-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (206.6 kB view details)

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

frozen_cub-0.2.10-cp313-cp313-macosx_11_0_arm64.whl (55.1 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for frozen_cub-0.2.10-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 6ad40bfb2d52a30c2b3fbf0c126b69bf5f2ccf70b79d45a36e69d9794893c773
MD5 4111f9ff5697a108838d37835bb7320e
BLAKE2b-256 29f831f49990f2c624b81135b87f315bc231398fb964b10c24137163aeaf8a7d

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.10-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.10-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.10-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 686feb3bbb15e315425208e67c110f985890fe633b5232389b7c9dd27775e7f3
MD5 e6f292d84339b6913e549a7c57869557
BLAKE2b-256 0c9df898b98e928b9fa5ba674cabb0c0e4e07ec3b9adeed993e4a882dc7e6de0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for frozen_cub-0.2.10-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 6bdc80b1702c39228a308041082bdd4b3f79ac9d20090b22050b643d9a8946ef
MD5 04f69e70b6c0642116c48302d0005c2a
BLAKE2b-256 cc780e710dd09a8831061cf2f1cd63cbb444b2b5cd2a4ac9e5a6e575db632875

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for frozen_cub-0.2.10-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4bd1139203dae7da46b5bd55a9f61ef194af5c52220c70f9f44988b00e6cbbf5
MD5 bb36d3b0c554f00a17b7c33b42cf4dd4
BLAKE2b-256 64ceb93ce65f1ba907b43eda5e41287d51e5046575d14a761ee93a0b2e70b3bf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for frozen_cub-0.2.10-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 2bee20027d76c4e1a943c02d9ddee5b2cbff33de3f149ad5c860f5a15109ebab
MD5 0a5ac46bf9976172c47bd9c63ea5a4fa
BLAKE2b-256 714f7d22e05f0d57e2bb373840c73556617c97dc1e2e6ca6af5f73712d71bd80

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.10-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.10-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.10-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 49e74167c3db15c5d98308b7e41bbe068e7119db07ca6f9004b0d08f3e74edb0
MD5 2157995ff5f16b58e073033b7a50d669
BLAKE2b-256 39c457a76c4afa7558aa3743b945b7d9d5c2b423ab3ae2407d40f1d96771a317

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for frozen_cub-0.2.10-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 89828daae52e020ad493e4a7b8bdc8f6b92bfaf09ceaad094644bbfbe412183a
MD5 1d41ca27cd9bdc292287f0375b960831
BLAKE2b-256 0e8abe7f8f5799d8542618ed1a44185113392c1e37dd812ff23dd1a8de35aec2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for frozen_cub-0.2.10-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8a4ad8c3c271cafc2e594af4536f6c65b42026cb6605b32f653df422ff4dc888
MD5 b3fdcde94f778b74f3f2d265f4b13992
BLAKE2b-256 7fed9596633cc894f971b78f77fd264d62b123ee9c3f37dc228908d7d4a09b19

See more details on using hashes here.

Provenance

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