❄️ cryostasis ❄️ -- Freeze arbitrary Python objects
Summary
cryostasis is a package that allows to turn arbitrary Python objects immutable.
The package is very lightweight and does not have any dependencies.
It offers the freeze and deepfreeze functions to freeze an object in-place.
When an object is frozen any modification to its attributes or items (i.e. assignment or deletion using the []-operator) will raise an ImmutableError.
All existing attributes, methods and items will still be accessible on the frozen instance though.
Since freeze acts in-place rather than applying a wrapper, the freezing affects all sites that hold references to the instance.
This ensures that the instance cannot be modified by some part of the codebase that just happened to get a reference earlier.
Frozen instances can be reverted back to their original state using the thaw and deepthaw functions.
Use Cases
Protecting central / global structures from accidental modification
You can usecryostasis in any scenario in which a central mutable instance is passed around to multiple sites, which should only have "read-only" access to its data.
This could be, for example, a configuration-driven application, where an initial configuration is loaded and then passed to different functions.
Another example would be the processing of large JSON responses that are passed to multiple functions.
Truly frozen dataclasses
You can use freeze / deepfreeze wherever you would have used a dataclass(frozen=True) but want to be a bit more thorough:
- unlike the
dataclassdecorator,freezecan also be used on instances of builtin types such as lists or dictionaries - also unlike the
dataclassdecorator,deepfreezewill freeze the instance and all of its attributes and items recursively
The freezing can be automated by adding freeze(self) / deepfreeze(self) in the dataclass' __post_init__.
An additional benefit of this approach over frozen=True is that the instance is not yet frozen in the context of __post_init__.
This eliminates the hassle of dealing with argument conversion on frozen dataclass instances.
Examples
freeze works by freezing an object in-place. For convenience, freeze also return a reference to the object.
Attributes and items remain accessible but any modifications to them will raise an cryostasis.ImmutableError.
On builtin, mutable types (e.g. list) the methods that modify the internal state of the instance also raise the same exception.
from cryostasis import freeze
class Dummy:
def __init__(self, value):
self.value = value
d = Dummy(value=5)
d.value = 42 # ok
freeze(d)
d.value = 9001 # raises ImmutableError
del d.value # raises ImmutableError
l = freeze([1,2,3])
l[0] # ok -- returns 1
l[0] = 5 # raises ImmutableError
del l[0] # raises ImmutableError
l.append(42) # raises ImmutableError
deepfreeze works the same way (it calls freeze internally) except that is recurses through the instances attributes and items, freezing all of them while traversing.
from cryostasis import deepfreeze
class Dummy:
def __init__(self, value):
self.value = value
self.a_dict = dict(a=1, b=2, c=[])
d = Dummy(value=[1,2,3])
deepfreeze(d)
d.value # ok -- returns <Frozen([1,2,3])>
d.value = 9001 # raises ImmutableError
del d.value # raises ImmutableError
d.value[0] # ok -- returns 1
d.value[0] = 42 # raises ImmutableError
del d.value[0] # raises ImmutableError
d.a_dict['c'] # ok -- returns <Frozen([])>
d.a_dict['c'].append(0) # raises ImmutableError
Documentation
The documentation of cryostasis is hosted on readthedocs.
Report Issues
This project lives on GitHub. If you encounter any issues or have feature requests, please open an issue using the project's Issues tab.
Metadata
Release files for cryostasis 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 256.0 kB
Release files / cryostasis-0.3.0-cp313-cp313-win_amd64.whl
| Download URL | cryostasis-0.3.0-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 16.9 kB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
d0544dd84401a52d52f3af0277e7691ced5d9d8d3ed1cc7e011731eafa0a6345
|
|
BLAKE2b-256 checksum How to use checksums |
88d189281ec0423342f28bce81d9260027cd28cc3a9d63f98978a69cfeaf4843
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 1, 2025.
Transparency logRelease files / cryostasis-0.3.0-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl
| Download URL | cryostasis-0.3.0-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 20.0 kB |
| Tags | CPython 3.13 Linux glibc 2.28+ x86-64 Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
a32e5bb2b0454d6293a3a836ceec471ed277fa4e873405526fd37df51f17b070
|
|
BLAKE2b-256 checksum How to use checksums |
90ea8252afba8e7b057e66f42b40fe2d2fcaf85d63e1994856b39808b04043cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 1, 2025.
Transparency logRelease files / cryostasis-0.3.0-cp313-cp313-macosx_10_13_universal2.whl
| Download URL | cryostasis-0.3.0-cp313-cp313-macosx_10_13_universal2.whl |
|---|---|
| Size | 14.7 kB |
| Tags | CPython 3.13 macOS 10.13+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
b4276e6314b1799fbf85c8a4b2cc66a338783b8dbb94cc24ddea666be44c9e7f
|
|
BLAKE2b-256 checksum How to use checksums |
9bde232975a19911ce4ec7dc15683ba466b34aaebbdd9f29473044138ffe65ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 1, 2025.
Transparency logRelease files / cryostasis-0.3.0-cp312-cp312-win_amd64.whl
| Download URL | cryostasis-0.3.0-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 16.9 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
5da770c1756444f14f239f32c1ee2b540f371ad6ff26fe963b9f3341ad3fd630
|
|
BLAKE2b-256 checksum How to use checksums |
10267520c9a97aafbbda1a457f5a30b1e900b27a866f43757f90f33f5f2cdd23
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 1, 2025.
Transparency logRelease files / cryostasis-0.3.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl
| Download URL | cryostasis-0.3.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 19.9 kB |
| Tags | CPython 3.12 Linux glibc 2.28+ x86-64 Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
af6d0e2edd0094720989ba2fc5b7d1476210c218151e124b9460552a210c994d
|
|
BLAKE2b-256 checksum How to use checksums |
d56b8f9678edf05443f4961db5f486ed7a01ba55cc09d883617b8165ebd4920e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 1, 2025.
Transparency logRelease files / cryostasis-0.3.0-cp312-cp312-macosx_10_13_universal2.whl
| Download URL | cryostasis-0.3.0-cp312-cp312-macosx_10_13_universal2.whl |
|---|---|
| Size | 14.7 kB |
| Tags | CPython 3.12 macOS 10.13+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
3d12e43e250ee760b2113a2756469acaaf0d85b1e1380e62809d76faf6e6e854
|
|
BLAKE2b-256 checksum How to use checksums |
8ab59498e185b90ccc3678f3cd87110cdb6769d824a9e3e3df140a870fe0af8e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 1, 2025.
Transparency logRelease files / cryostasis-0.3.0-cp311-cp311-win_amd64.whl
| Download URL | cryostasis-0.3.0-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 16.9 kB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
c31b08f2ac1a4d85b78ba7bc3980338e60625f98a1dd4275f9097272ef9cf780
|
|
BLAKE2b-256 checksum How to use checksums |
c72d7337c01929c9c2ca7c07d60c68583f67e57474c9e48023df3163cf0144e2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 1, 2025.
Transparency logRelease files / cryostasis-0.3.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl
| Download URL | cryostasis-0.3.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 19.6 kB |
| Tags | CPython 3.11 Linux glibc 2.28+ x86-64 Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
4d6460c68992ac0ef7d45390d496bcef598c246ce5ab7806e40d42440f586778
|
|
BLAKE2b-256 checksum How to use checksums |
bf6fe47032fcd4c78f3ad50acedc7fbadc543cebb206124936791bec08b82df5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 1, 2025.
Transparency logRelease files / cryostasis-0.3.0-cp311-cp311-macosx_10_9_universal2.whl
| Download URL | cryostasis-0.3.0-cp311-cp311-macosx_10_9_universal2.whl |
|---|---|
| Size | 14.6 kB |
| Tags | CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
ddc0f6138bc389a56a36a063d8808751e6ab781e7756646c9e686c309923ad4e
|
|
BLAKE2b-256 checksum How to use checksums |
1e58ad2849bc73e73bc97c15cb78d070cea473e717cd8a0dcde372fe9f169711
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 1, 2025.
Transparency logRelease files / cryostasis-0.3.0-cp310-cp310-win_amd64.whl
| Download URL | cryostasis-0.3.0-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 16.9 kB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
fdee2ebc4421459b4234a7ee6098ddf1b61e067e0dc911b165f30952859fd20d
|
|
BLAKE2b-256 checksum How to use checksums |
c4d70420c377440cee1642a71de63cfc87627793c0fc6fc28c6574cdb4b2dc85
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 1, 2025.
Transparency logRelease files / cryostasis-0.3.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl
| Download URL | cryostasis-0.3.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 19.5 kB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
ab031535a786398c366f323a0461c2958100751fb6f320d239b451aadf723e25
|
|
BLAKE2b-256 checksum How to use checksums |
4d98c6f78a9ab59fefa58f7816917acba9d7d4d013942dc86060ff933c97172d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 1, 2025.
Transparency logRelease files / cryostasis-0.3.0-cp310-cp310-macosx_10_9_universal2.whl
| Download URL | cryostasis-0.3.0-cp310-cp310-macosx_10_9_universal2.whl |
|---|---|
| Size | 14.6 kB |
| Tags | CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
302ee4e89ad09c2f913357d5711e320183a964136f81108e6db1c3f9c69654f3
|
|
BLAKE2b-256 checksum How to use checksums |
f16b59e1652981206b0ee51407c643b5a9641d48f7f4327a83b8995b4abcb952
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 1, 2025.
Transparency logRelease files / cryostasis-0.3.0-cp39-cp39-win_amd64.whl
| Download URL | cryostasis-0.3.0-cp39-cp39-win_amd64.whl |
|---|---|
| Size | 16.9 kB |
| Tags | CPython 3.9 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
d72d0fe670ba0448674ed1609f9b808946c24f014b3c1a364e8a3af98b702a8f
|
|
BLAKE2b-256 checksum How to use checksums |
99fdf728c1f89adc0770d0a4038197d0570bad1a4c344699995ef3073ea73f4d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 1, 2025.
Transparency logRelease files / cryostasis-0.3.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl
| Download URL | cryostasis-0.3.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 19.3 kB |
| Tags | CPython 3.9 Linux glibc 2.28+ x86-64 Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
cad45d6d509c442e9426aa3ed2a1d449347d296bf092b860fadaf76fc54a0cfc
|
|
BLAKE2b-256 checksum How to use checksums |
a6949e296163abc798b4bda770ce23a94f219d2411b838d80305f10934678f8d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 1, 2025.
Transparency logRelease files / cryostasis-0.3.0-cp39-cp39-macosx_10_9_universal2.whl
| Download URL | cryostasis-0.3.0-cp39-cp39-macosx_10_9_universal2.whl |
|---|---|
| Size | 14.6 kB |
| Tags | CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
04dae51c8b4c0e8496094e071938833cb2db7519aca787815627cff78bc380ad
|
|
BLAKE2b-256 checksum How to use checksums |
b095772c533d2a4bda5e6b41b78b360a830dc439aec26ba3a3ece9dc314e0af9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 1, 2025.
Transparency logSecurity for cryostasis 0.3.0
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.
Full provenance
All 15 files in this release have been uploaded with provenance metadata.
Attestation for cryostasis-0.3.0-cp313-cp313-win_amd64.whl
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 1, 2025.
Transparency logA 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.