Skip to main content

creates the next immutable object by simply modifying the current one

Project description


Create the next immutable object by simply modifying the current one

This is a Python port of immer.

pip install immerframe

Want to do a deep update on a Python data structure without mutating it? No problem:

from immerframe import Proxy, produce

Ant = namedtuple('Ant', 'age')
nested = {
    'foo': [

proxy = Proxy()
proxy['foo'][0].age += 1
proxy['qux'] = 99

new_nested = produce(proxy, nested)

new_nested will now equal

    'foo': [
    'qux': 99,

while nested will remain unchanged.

"What about my typing?"

from typing import cast

Cat = namedtuple('Cat', 'name')

proxy = cast(Cat, Proxy())
# continue as before but with autocomplete and type checking! = 'Felix'

immerframe uses structural sharing, so should be efficient in most cases:

d = {'foo': 1}
l = [d]

proxy = Proxy()
new_l = produce(proxy, l)
assert new_l == [d, 100]
assert new_l[0] is d

immerframe supports:

  • dicts
  • lists
  • sets
  • tupless
  • namedtupless
  • attrss


immerframe comes with a Lens class to help with path reuse:

d = {'foo': [1, 2, 3, 4]}

lens = Lens(Proxy()['foo'][1])

new_d = lens.set(d, 100)
assert new_d == {'foo': [1, 100, 3, 4]}
assert d == {'foo': [1, 2, 3, 4]}
assert lens.get(d) == 2


immerframe currently has an attrs plugin, registering plugins is pretty easy, just mutate the immerframe.plugins list (see here for the structure of the existing attr plugin).

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

immerframe-0.0.3.tar.gz (4.3 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page