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

Uploaded CPython 3.14Windows x86-64

frozen_cub-0.1.13-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.13-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.3 MB view details)

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

frozen_cub-0.1.13-cp314-cp314-macosx_11_0_arm64.whl (241.8 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

frozen_cub-0.1.13-cp313-cp313-win_amd64.whl (44.4 kB view details)

Uploaded CPython 3.13Windows x86-64

frozen_cub-0.1.13-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.13-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.3 MB view details)

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

frozen_cub-0.1.13-cp313-cp313-macosx_11_0_arm64.whl (239.8 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

frozen_cub-0.1.13-cp312-cp312-win_amd64.whl (44.4 kB view details)

Uploaded CPython 3.12Windows x86-64

frozen_cub-0.1.13-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.13-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.3 MB view details)

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

frozen_cub-0.1.13-cp312-cp312-macosx_11_0_arm64.whl (243.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for frozen_cub-0.1.13-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 afb357645bfe920af658a92cda24cbfb60789767f991cbe7c249c0a3fb7c89b6
MD5 f3f579e1e15d923e3807814d50da8061
BLAKE2b-256 e660a540aa424a920840969a17320224ae9ea39385b9c7c03a40632cece86dc4

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.1.13-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.13-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.13-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 581e68eee6f2559a420c9c0795ebd15757f0ea084cf9dae5465c8f200b0586b0
MD5 67865a5f9d14d7134b133151b4a5ed83
BLAKE2b-256 bd6281374c034b7fc294e54cba8c88451d20f93355a24faa1a243df5507fec26

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for frozen_cub-0.1.13-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 72707724d2379af5feed3cf2744624de1b140c8cd50fcb464d9f1fbc0b60d515
MD5 08f5816508b326ab856b9b6f4e6c760c
BLAKE2b-256 f3902f3a80802985f2770681bac1aa254046c177687222a071d004a0e0eccdb8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for frozen_cub-0.1.13-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a8d20a57857d637192e7b5de5a8b5d247181670179a1f49375aa4544a9e40be8
MD5 b684027e584907605b5d5e4389ef1180
BLAKE2b-256 fa5ca76f4eefeaca9569c4ae5c66b2894a26ebeeabb5c14d76f8892238f693a5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for frozen_cub-0.1.13-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 ae82894643e91ff0365521e51fb83ee34503d2615bebd9f5323e57b659dda7bb
MD5 789264244807a3e0da1b02f5ac8f9668
BLAKE2b-256 38aa3e8fcfd05818dcb3711824656c29d47995cbb1ea26e96bc71bea94c339c3

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.1.13-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.13-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.13-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 856ef6767a727942b252fe81a19e7ade15142cb2a28e8c6d66ab01264fc1dcc2
MD5 3107a326fa820f73f575cb60bc35d92a
BLAKE2b-256 cfb398ce7f90dcf04fabcb02673371d9b0de91abdb441d5bd62caaa561f2e1eb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for frozen_cub-0.1.13-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a3a5a66e1a4eec36ad8bd780d47d5f306a54d7d1cb455c36db3efce13431337e
MD5 4d73f7ced856e2a89351dc5148681128
BLAKE2b-256 597cf15818457f0cf2d7896474f61c9c1a2921cd9a0d76175329cd77186f2f9c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for frozen_cub-0.1.13-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b6a71184776543b58bec25e9f16e1f54a6476e540626c439f58ea378d17627a7
MD5 58ee38bdfc3fdd519c875fdc7782f071
BLAKE2b-256 abae815f9bc4ea391bab2a058f3e824b4d35d11aba3223792d8aab8e145321ed

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.1.13-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.13-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for frozen_cub-0.1.13-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 1a82bf6573a69c8144509864728b6ec5d2dc1194cec3864314eb55d24c039134
MD5 56ae223537efb39366d29e627309a5ba
BLAKE2b-256 efb724a0d3c4827b4f6e1a07d2b474b21c20c4fdbdef657923e066333c0b9e03

See more details on using hashes here.

Provenance

The following attestation bundles were made for frozen_cub-0.1.13-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.13-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.13-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 625c223abaf4f288954f3ef13f9a2a41948d1b0c57d0fae971d9d3ddf4e4a16e
MD5 f885f95d7ea48d077cc271af330112d8
BLAKE2b-256 f6ba7968aa7c900ba58645051abe4be9f06c64594f8e3c52c08644e0dd998a5b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for frozen_cub-0.1.13-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9a25a31f4502d33f8c16d7fe0d9b455783bf823f0ca2aaa8c809b08e529e1c3d
MD5 62ba20b7621c1afc957fa4e72d9d8533
BLAKE2b-256 7a6114d42c84eb4414b3d98c7caf4ae82cfb3880d52167329fafd31bbac418b1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for frozen_cub-0.1.13-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 76878f640cf3fcb51a17a36cb5156a2bf41983de7ca549b6dd2e1b3d448bea89
MD5 bf97a54ed1808fbb073018661b5b70e6
BLAKE2b-256 ef417bd0fe17588009a28725636b1fbf26c3aa12b6471d28ae59ce2ff9383c93

See more details on using hashes here.

Provenance

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