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

Uploaded CPython 3.14Windows x86-64

frozen_cub-0.2.8-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (189.8 kB view details)

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

frozen_cub-0.2.8-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (197.7 kB view details)

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

frozen_cub-0.2.8-cp314-cp314-macosx_11_0_arm64.whl (54.7 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

frozen_cub-0.2.8-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (190.3 kB view details)

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

frozen_cub-0.2.8-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (197.6 kB view details)

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

frozen_cub-0.2.8-cp313-cp313-macosx_11_0_arm64.whl (54.5 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: frozen_cub-0.2.8-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 15.6 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.8-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 c9df94e547151dfb931824441c107f3beec01f3aeaf719903b585022a3264ed9
MD5 de457d5db3e7c8e40b13519a3a3cc942
BLAKE2b-256 7361e595712344f44cac3c6e18b117e24d732ba879c693bc832590d031b349c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.8-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.8-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.8-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d88afcd76ed90abb7a53cb660cada4055c2a9002d9fe8195747059d47ca47bea
MD5 7801fbe244dd14cd5268e66a814beaa3
BLAKE2b-256 72d7ae5c91000d1789b89535570d19b4d19080def1142905214e34c039ec6681

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for frozen_cub-0.2.8-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 da3fecee8edf88c199d5124d4ccb6010bce0dcf8355de748cca62244f76dcd88
MD5 f924f2ae3aee5d636a683270e5663d94
BLAKE2b-256 bfd7f486f63d4ee5818a87363e2149a01a60a364a4ae62c7df9825b630098b49

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for frozen_cub-0.2.8-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 63426db487f7b775de24e2db12e24de7fdb6ffeae2cd5b0ef9b89e9f131a4362
MD5 050ae455ab480f86162621454932b358
BLAKE2b-256 124d0ec62ddcd4864c3dbf6174c77150b61da520bd037cb518b7e5a8e1be2ead

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: frozen_cub-0.2.8-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 15.6 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.8-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 5ae3bdbf85d7b44fc8d75f6f94a3ead308a60384118e061d4b55fa21d12f3e98
MD5 36cbc0724b86fe668dcc4bfe635de64b
BLAKE2b-256 ec7fd725da7079866f9557ec7770569f5cc51e8ae9bd63db5c25c7c009dc4e77

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.2.8-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.8-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.8-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 453685a522d41c96432040dab8dd42bd5c7a44d89abafd29ab6d04c5dfb0e544
MD5 1ea4e5e5878a44af1f239630e974609a
BLAKE2b-256 f38cf7315380081bcd6bb2ba017b301779d8ca62ef2b898b4dc4467ed0a63216

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for frozen_cub-0.2.8-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 53706a8e117b6d4d7b543ab67c5bd04da9c83632640ec1cde433167b61fa4421
MD5 b42b5ac3a857281f413ae899d90ce80e
BLAKE2b-256 af70b48a5b6608dfe5618494b9633dbd1cb7bf1b32a79ac46984897ea87f6af5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for frozen_cub-0.2.8-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 79c571634b938d3df751a42cd048fc560b44629234912e358230986ad39ca60f
MD5 9daa6789f3ba34e511181b1659ed6c7e
BLAKE2b-256 8fa298754cc33fa9eb7e78587278dd5dca5df873d4b15764beadcb257839b496

See more details on using hashes here.

Provenance

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