Skip to main content

PyPI version shields.io PyPI pyversions Ruff Checked with mypy

arcticfreeze

Note: This is a fork of KerstenBreuer/arcticfreeze maintained by the German Human Genome-Phenome Archive (GHGA). It was created to bring in fixes and updates required by GHGA-related projects. Many thanks to Kersten Breuer for the initial implementation. The distribution is published as ghga-arcticfreeze, but the import path remains arcticfreeze, so it is a drop-in replacement for the upstream package.

Enjoy Python on the rocks with deeply (recursively) frozen data structures.

Description

Python's built-in immutable types only go one level deep: a tuple may still contain a list, and a frozenset cannot contain a dict at all. arcticfreeze closes that gap by recursively converting a nested data structure into an immutable counterpart.

It provides:

  • freeze – a function that deep freezes an arbitrary object. It walks the object tree bottom-up and replaces every mutable container with an immutable equivalent (list/deque → tuple, dict → FrozenDict, set → frozenset), leaving already-immutable values untouched.
  • FrozenDict – a hashable, immutable Mapping (built on immutabledict) with first-class type-hint support and out-of-the-box Pydantic v2 integration (validation, JSON schema, and serialization).
  • Converter – an extension point for teaching freeze how to handle your own types, including a priority mechanism to override the standard converters.

Freezing is useful wherever shared data must not be mutated by accident: configuration objects, cached values, dictionary keys, or any value that should be hashable and safe to pass around.

Installation

Requirements

  • Python 3.11+

Install from PyPI

pip install ghga-arcticfreeze

To use the FrozenDict type within Pydantic models, install the optional pydantic extra:

pip install "ghga-arcticfreeze[pydantic]"

Usage

Deep freezing

from arcticfreeze import FrozenDict, freeze

original = {"a": [1, 2, {"b": {"c", "d"}}]}
frozen = freeze(original)

# The nested list became a tuple, the nested dicts became FrozenDicts,
# and the nested set became a frozenset:
assert frozen == FrozenDict({"a": (1, 2, FrozenDict({"b": frozenset({"c", "d"})}))})

# The result is hashable and cannot be modified:
hash(frozen)

Custom types are supported by providing additional converters:

from arcticfreeze import Converter, freeze


class Point:
    def __init__(self, x: int, y: int):
        self.x = x
        self.y = y


point_converter = Converter(
    input_type=Point,
    convert=lambda obj, freeze_child: (freeze_child(obj.x), freeze_child(obj.y)),
)

assert freeze(Point(1, 2), add_converters=[point_converter]) == (1, 2)

FrozenDict in Pydantic models

from arcticfreeze import FrozenDict
from pydantic import BaseModel


class Config(BaseModel):
    parameters: FrozenDict[str, int]


config = Config(parameters={"a": 1})

# The mapping is validated and converted into a FrozenDict:
assert isinstance(config.parameters, FrozenDict)

# It serializes to a plain dict in JSON mode and stays a FrozenDict in Python mode:
assert config.model_dump(mode="json") == {"parameters": {"a": 1}}
assert isinstance(config.model_dump()["parameters"], FrozenDict)

Development

This package is a member of the GHGA monorepo and is developed from the repository root rather than on its own. The repository ships a devcontainer with the whole toolchain: open it in VS Code and run Remote-Containers: Reopen in Container, or set the environment up directly with just sync.

The usual tasks, run from the repository root (see ADR-0034 for the full recipe list):

just sync                         # install every member plus the shared dev toolchain
just test libs/ghga-arcticfreeze  # this member's test suite
just lint                         # ruff check + format check across the workspace

License

This repository is free to use and modify according to the Apache 2.0 License.

Metadata

Release files for ghga-arcticfreeze 1.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ghga-arcticfreeze 1.1.3
File Size Uploaded Provenance Actions
ghga_arcticfreeze-1.1.3.tar.gz 15.4 kB Without provenance Details for ghga_arcticfreeze-1.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ghga-arcticfreeze 1.1.3
File Interpreter ABI Platform Actions
ghga_arcticfreeze-1.1.3-py3-none-any.whl Python 3 none any Details for ghga_arcticfreeze-1.1.3-py3-none-any.whl

Total release size: 34.7 kB

Release files / ghga_arcticfreeze-1.1.3.tar.gz

Download URL ghga_arcticfreeze-1.1.3.tar.gz
Size 15.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b6bf21abe2bf0241138b7453005cc8ac428754ded5479b76c27902e1a7487a81
BLAKE2b-256 checksum
How to use checksums
39f2829ceeb01b77110ad281155379b6a088e05707bc76e45cef90a7f5fb708e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / ghga_arcticfreeze-1.1.3-py3-none-any.whl

Download URL ghga_arcticfreeze-1.1.3-py3-none-any.whl
Size 19.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a69829b9f3d908e1472cc52362daf011b7295fffa73948b23b049a5b6ec4e487
BLAKE2b-256 checksum
How to use checksums
084802b8c3e120d81432830f23190eafd4b083919e864c77471fcb4687902129
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for ghga-arcticfreeze 1.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page