Skip to main content

Python package to deflate and re-inflate dictionaries.

Project description

Travis CI build SonarCloud Quality SonarCloud Maintainability Codacy Maintainability Maintainability Pypi project Pypi total project downloads

Python package to deflate and re-inflate dictionaries.

How do I install this package?

As usual, just download it using pip:

pip install deflate_dict

Tests Coverage

Since some software handling coverages sometime get slightly different results, here’s three of them:

Coveralls Coverage SonarCloud Coverage Code Climate Coverate

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="_")

# {'a_0_b': (0, 1, 2), 'a_1_c': [1, 2, 3], 'd': 4}

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=True))

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

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

deflate_dict-1.0.9.tar.gz (4.9 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: deflate_dict-1.0.9.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.7.6

File hashes

Hashes for deflate_dict-1.0.9.tar.gz
Algorithm Hash digest
SHA256 44d6415c3ab5c6f591c87126a567578f18da4a740f333a0a166b27105a5597c0
MD5 f9ca716f53588bb8986f7ae52930826e
BLAKE2b-256 8d96d88292145ad5e16f31b63963623cb86efbf224b093c7221388c0f1fd84d2

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page