Skip to main content

🎈🌵 Deflate Dict

pip python license downloads mypy Github Actions

Python package to deflate 🌵 and re-inflate 🎈 nested dictionaries.

How do I install this package?

As usual, just download it using pip:

pip install deflate_dict

Deflating a dictionary

A dictionary will be deflated down to its smallest non-further iterable elements, defined as those not containing lists or dictionaries.

from deflate_dict import deflate
D = {
    "a": [
        {
            "b": (0, 1, 2)
        },
        {
            "c": [1, 2, 3]
        }
    ]
}
result = deflate(D, sep="_")

# {'str(a)_listIndex(0)_str(b)': (0, 1, 2), 'str(a)_listIndex(1)_str(c)': [1, 2, 3]}

Inflate a dictionary

To reinflate a dictionary to its forgotten glory, just go with:

from deflate_dict import inflate
D = {"a_0_b": (0, 1, 2), "a_1_c": [1, 2, 3], "d": 4}

result = inflate(D, sep="_")

# {'a': [{'b': (0, 1, 2)}, {'c': [1, 2, 3]}], 'd': 4}

Handling and restoring mixed types

To deflate and re-inflate mixed types and restore them to the original type you can use the type_encode_key keyword:

from deflate_dict import deflate

D = {
    "a":[
        {
            "b":(0,1,2)
        },
        {
            "c": [1,2,3]
        }
    ]
}

print(deflate(D, sep="_", type_encode_key=False))

# {
# 'a_listIndex(0)_b': (0, 1, 2),
# 'a_listIndex(1)_c': [1, 2, 3]
# }

print(deflate(D, sep="_", type_encode_key=True))

# {
#    'str(a)_listIndex(0)_str(b)': (0, 1, 2),
#    'str(a)_listIndex(1)_str(c)': [1, 2, 3]
# }

License

This software is distributed under MIT license.

Download files

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

Source Distribution

deflate_dict-1.2.2.tar.gz (6.9 kB view details)

Uploaded Source

File details

Details for the file deflate_dict-1.2.2.tar.gz.

File metadata

  • Download URL: deflate_dict-1.2.2.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.9

File hashes

Hashes for deflate_dict-1.2.2.tar.gz
Algorithm Hash digest
SHA256 a51f72562a2056118c6b0915b4ac46a483cc329b43d13d759307e4c027ea20ea
MD5 15d7b8e7602ec37fae33a8fa3a560fbe
BLAKE2b-256 2f05ca5ea149d91d172b9b9d64547b33a87e9613038deb4c8c7bbaf76e26a4be

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.2.2 This release

1 file

1.2.1

1 file

1.2.0

1 file

1.0.11

1 file

1.0.10

1 file

1.0.9

1 file

1.0.8

1 file

1.0.7

1 file

1.0.6

1 file

1.0.5

1 file

1.0.4

1 file

1.0.3

1 file

1.0.2

1 file

1.0.1

1 file

1.0.0

1 file

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