Skip to main content

immerframe

Intuitively perform deep updates on python objects

  • without mutating them
  • while being efficient via structural sharing - no deepcopy
  • while maintaining type correctness

This is (almost) a Python port of immer.

pip install immerframe

First, let's import some stuff

from dataclasses import dataclass
from immerframe import Proxy

Now, consider the data:

@dataclass
class Ant:
    age: int

ant_10 = Ant(age=10)
ant_20 = Ant(age=20)
nested = {
    "ants": [ant_10, ant_20, None],
}

let's pretend to mutate it

with Proxy(nested) as (p, new_nested):
    p["ants"][0].age += 1
    p["ants"].pop()
    p["foo"] = 99

(note p and new_nested should have the correct types in mypy)

nested will remain the same

assert nested == {
    "ants": [ant_10, ant_20, None],
}

new_nested will be nested, but with the mutations with specified in the with Proxy(...) block

assert new_nested == { "ants": [Ant(age=11), ant_20], "foo": 99, }


but it _won't_ be a deep copy

```python
assert new_nested["ants"][1] is ant_20

immerframe supports most thing's that can be copyed

Things to remember

Mutating the same thing in a block twice may not do what you'd expect in the following type of case:

with Proxy([1]) as (l, new_l):
    l[0] += 5
    l[0] += 10

will give l == [11]

Use keys rather than references to loop over and mutate nested dicts/lists:

with Proxy(new_nested) as (p, new_nested):
    for k in new_nested:
        p[k] += 1
    for i, n in enumerate(new_nested["ants"]):
        if n.age < 15:
            p["ants"][i].age + 10

TODO

  • implement all dunder methods
  • finish typing

Metadata

Release files for immerframe 0.1.0

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

Source distribution (sdist)

Source distribution for immerframe 0.1.0
File Size Uploaded Provenance
immerframe-0.1.0.tar.gz 5.0 kB Without provenance Details

Release files / immerframe-0.1.0.tar.gz

Download URL immerframe-0.1.0.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b683bcc7850195601fffdfd99798e4800277e948564eaadc46de3b5b6bac5a16
BLAKE2b-256 checksum
How to use checksums
3f999b7a59060843251b50dae37cdd11a462850a19393be4f4a0d09c418010b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.5

Security for immerframe 0.1.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.

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