Skip to main content

No project description provided

Project description

❄️ 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 dataclass decorator, freeze can also be used on instances of builtin types such as lists or dictionaries
  • also unlike the dataclassdecorator, deepfreeze will 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.

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.

cryostasis-0.3.0-cp313-cp313-win_amd64.whl (16.9 kB view details)

Uploaded CPython 3.13Windows x86-64

cryostasis-0.3.0-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl (20.0 kB view details)

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

cryostasis-0.3.0-cp313-cp313-macosx_10_13_universal2.whl (14.7 kB view details)

Uploaded CPython 3.13macOS 10.13+ universal2 (ARM64, x86-64)

cryostasis-0.3.0-cp312-cp312-win_amd64.whl (16.9 kB view details)

Uploaded CPython 3.12Windows x86-64

cryostasis-0.3.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl (19.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

cryostasis-0.3.0-cp312-cp312-macosx_10_13_universal2.whl (14.7 kB view details)

Uploaded CPython 3.12macOS 10.13+ universal2 (ARM64, x86-64)

cryostasis-0.3.0-cp311-cp311-win_amd64.whl (16.9 kB view details)

Uploaded CPython 3.11Windows x86-64

cryostasis-0.3.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl (19.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

cryostasis-0.3.0-cp311-cp311-macosx_10_9_universal2.whl (14.6 kB view details)

Uploaded CPython 3.11macOS 10.9+ universal2 (ARM64, x86-64)

cryostasis-0.3.0-cp310-cp310-win_amd64.whl (16.9 kB view details)

Uploaded CPython 3.10Windows x86-64

cryostasis-0.3.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl (19.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

cryostasis-0.3.0-cp310-cp310-macosx_10_9_universal2.whl (14.6 kB view details)

Uploaded CPython 3.10macOS 10.9+ universal2 (ARM64, x86-64)

cryostasis-0.3.0-cp39-cp39-win_amd64.whl (16.9 kB view details)

Uploaded CPython 3.9Windows x86-64

cryostasis-0.3.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl (19.3 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

cryostasis-0.3.0-cp39-cp39-macosx_10_9_universal2.whl (14.6 kB view details)

Uploaded CPython 3.9macOS 10.9+ universal2 (ARM64, x86-64)

File details

Details for the file cryostasis-0.3.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: cryostasis-0.3.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 16.9 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for cryostasis-0.3.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 d0544dd84401a52d52f3af0277e7691ced5d9d8d3ed1cc7e011731eafa0a6345
MD5 0debf5c777b0d03785391f9871e358a2
BLAKE2b-256 88d189281ec0423342f28bce81d9260027cd28cc3a9d63f98978a69cfeaf4843

See more details on using hashes here.

Provenance

The following attestation bundles were made for cryostasis-0.3.0-cp313-cp313-win_amd64.whl:

Publisher: build_wheels.yaml on IljaManakov/cryostasis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cryostasis-0.3.0-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cryostasis-0.3.0-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a32e5bb2b0454d6293a3a836ceec471ed277fa4e873405526fd37df51f17b070
MD5 bc95c9886907d0e9efd3d526f392efdb
BLAKE2b-256 90ea8252afba8e7b057e66f42b40fe2d2fcaf85d63e1994856b39808b04043cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for cryostasis-0.3.0-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build_wheels.yaml on IljaManakov/cryostasis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cryostasis-0.3.0-cp313-cp313-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for cryostasis-0.3.0-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 b4276e6314b1799fbf85c8a4b2cc66a338783b8dbb94cc24ddea666be44c9e7f
MD5 7110932b7694bb34f41d0f43a5bef989
BLAKE2b-256 9bde232975a19911ce4ec7dc15683ba466b34aaebbdd9f29473044138ffe65ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for cryostasis-0.3.0-cp313-cp313-macosx_10_13_universal2.whl:

Publisher: build_wheels.yaml on IljaManakov/cryostasis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cryostasis-0.3.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: cryostasis-0.3.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 16.9 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for cryostasis-0.3.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 5da770c1756444f14f239f32c1ee2b540f371ad6ff26fe963b9f3341ad3fd630
MD5 1b1bb16b42d107ed1098a9e85a0082d9
BLAKE2b-256 10267520c9a97aafbbda1a457f5a30b1e900b27a866f43757f90f33f5f2cdd23

See more details on using hashes here.

Provenance

The following attestation bundles were made for cryostasis-0.3.0-cp312-cp312-win_amd64.whl:

Publisher: build_wheels.yaml on IljaManakov/cryostasis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cryostasis-0.3.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cryostasis-0.3.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 af6d0e2edd0094720989ba2fc5b7d1476210c218151e124b9460552a210c994d
MD5 c24504128bf5cd1bfa61ac3f85fd13b3
BLAKE2b-256 d56b8f9678edf05443f4961db5f486ed7a01ba55cc09d883617b8165ebd4920e

See more details on using hashes here.

Provenance

The following attestation bundles were made for cryostasis-0.3.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build_wheels.yaml on IljaManakov/cryostasis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cryostasis-0.3.0-cp312-cp312-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for cryostasis-0.3.0-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 3d12e43e250ee760b2113a2756469acaaf0d85b1e1380e62809d76faf6e6e854
MD5 f17f01b5c742849dde3c8043ac421584
BLAKE2b-256 8ab59498e185b90ccc3678f3cd87110cdb6769d824a9e3e3df140a870fe0af8e

See more details on using hashes here.

Provenance

The following attestation bundles were made for cryostasis-0.3.0-cp312-cp312-macosx_10_13_universal2.whl:

Publisher: build_wheels.yaml on IljaManakov/cryostasis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cryostasis-0.3.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: cryostasis-0.3.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 16.9 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for cryostasis-0.3.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c31b08f2ac1a4d85b78ba7bc3980338e60625f98a1dd4275f9097272ef9cf780
MD5 376182a6664b93eeae36292f0d9eb960
BLAKE2b-256 c72d7337c01929c9c2ca7c07d60c68583f67e57474c9e48023df3163cf0144e2

See more details on using hashes here.

Provenance

The following attestation bundles were made for cryostasis-0.3.0-cp311-cp311-win_amd64.whl:

Publisher: build_wheels.yaml on IljaManakov/cryostasis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cryostasis-0.3.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cryostasis-0.3.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4d6460c68992ac0ef7d45390d496bcef598c246ce5ab7806e40d42440f586778
MD5 0d4c150c2e49c41c7648bd139e6297fa
BLAKE2b-256 bf6fe47032fcd4c78f3ad50acedc7fbadc543cebb206124936791bec08b82df5

See more details on using hashes here.

Provenance

The following attestation bundles were made for cryostasis-0.3.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build_wheels.yaml on IljaManakov/cryostasis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cryostasis-0.3.0-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for cryostasis-0.3.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 ddc0f6138bc389a56a36a063d8808751e6ab781e7756646c9e686c309923ad4e
MD5 7a367889c0c3223f37eca5d92d7fbf78
BLAKE2b-256 1e58ad2849bc73e73bc97c15cb78d070cea473e717cd8a0dcde372fe9f169711

See more details on using hashes here.

Provenance

The following attestation bundles were made for cryostasis-0.3.0-cp311-cp311-macosx_10_9_universal2.whl:

Publisher: build_wheels.yaml on IljaManakov/cryostasis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cryostasis-0.3.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: cryostasis-0.3.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 16.9 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for cryostasis-0.3.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 fdee2ebc4421459b4234a7ee6098ddf1b61e067e0dc911b165f30952859fd20d
MD5 de8608461664bf74ffd1240b52650a27
BLAKE2b-256 c4d70420c377440cee1642a71de63cfc87627793c0fc6fc28c6574cdb4b2dc85

See more details on using hashes here.

Provenance

The following attestation bundles were made for cryostasis-0.3.0-cp310-cp310-win_amd64.whl:

Publisher: build_wheels.yaml on IljaManakov/cryostasis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cryostasis-0.3.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cryostasis-0.3.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ab031535a786398c366f323a0461c2958100751fb6f320d239b451aadf723e25
MD5 b3e39942da2370c03dc8fa7263732f27
BLAKE2b-256 4d98c6f78a9ab59fefa58f7816917acba9d7d4d013942dc86060ff933c97172d

See more details on using hashes here.

Provenance

The following attestation bundles were made for cryostasis-0.3.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build_wheels.yaml on IljaManakov/cryostasis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cryostasis-0.3.0-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for cryostasis-0.3.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 302ee4e89ad09c2f913357d5711e320183a964136f81108e6db1c3f9c69654f3
MD5 719928ef78d133549cf217b9a3222ee1
BLAKE2b-256 f16b59e1652981206b0ee51407c643b5a9641d48f7f4327a83b8995b4abcb952

See more details on using hashes here.

Provenance

The following attestation bundles were made for cryostasis-0.3.0-cp310-cp310-macosx_10_9_universal2.whl:

Publisher: build_wheels.yaml on IljaManakov/cryostasis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cryostasis-0.3.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: cryostasis-0.3.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 16.9 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for cryostasis-0.3.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 d72d0fe670ba0448674ed1609f9b808946c24f014b3c1a364e8a3af98b702a8f
MD5 e13b3773e6e635a746de0af1b65bb7e1
BLAKE2b-256 99fdf728c1f89adc0770d0a4038197d0570bad1a4c344699995ef3073ea73f4d

See more details on using hashes here.

Provenance

The following attestation bundles were made for cryostasis-0.3.0-cp39-cp39-win_amd64.whl:

Publisher: build_wheels.yaml on IljaManakov/cryostasis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cryostasis-0.3.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cryostasis-0.3.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cad45d6d509c442e9426aa3ed2a1d449347d296bf092b860fadaf76fc54a0cfc
MD5 fcef952097e94bc9cde3826ca20e209a
BLAKE2b-256 a6949e296163abc798b4bda770ce23a94f219d2411b838d80305f10934678f8d

See more details on using hashes here.

Provenance

The following attestation bundles were made for cryostasis-0.3.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build_wheels.yaml on IljaManakov/cryostasis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cryostasis-0.3.0-cp39-cp39-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for cryostasis-0.3.0-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 04dae51c8b4c0e8496094e071938833cb2db7519aca787815627cff78bc380ad
MD5 37482e91dc69765e89e0358cf1ab2524
BLAKE2b-256 b095772c533d2a4bda5e6b41b78b360a830dc439aec26ba3a3ece9dc314e0af9

See more details on using hashes here.

Provenance

The following attestation bundles were made for cryostasis-0.3.0-cp39-cp39-macosx_10_9_universal2.whl:

Publisher: build_wheels.yaml on IljaManakov/cryostasis

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