Skip to main content

A dictionary that can be flattened and re-inflated

Project description

deflatable-dict

A dictionary that can be flattened and re-inflated. Particularly useful if you're interacting with yaml, for example.

Build PyPI version

Installation

with pip:

pip install deflatable-dict

deflatable-dict does not have any dependencies beyond standard python libraries.

Instantiation

from deflatabledict import DeflatableDict

dd = DeflatableDict({
    "a": {
        "1": True,
        "2": False,
    },
    "b": 20,
})

dd["a.1"] # True
dd["a.2"] # False
dd["b"] # 20
dd["a"] # { "1": True, "2": False }

Deflation

A DeflatableDict can be deflated with .deflate(). This returns a standard dictionary object with flattened keys constructed by concatenating the nested keys with the DeflatableDict's delimiter. A DeflatableDict uses it's deflated form for its string representation.

Delimiter

A DeflatableDict can have it's delimiter specified by passing the desired delimiter as the sep parameter to the DeflatableDict constructor. By default the delimiter if ..

Inflation

A DeflatableDict will automatically inflate any values that are inserted into it. For example:

from deflatabledict import DeflatableDict

dd = DeflatableDict()
dd["a.1"] = True
dd["a.2"] = False

dd["a"] # { "1": True, "2": False }

Development

Code style: black

This project uses .devcontainer to describe the environment to use for development. You may use the environment described in this directory (it integrates automatically with vscode's 'remote containers' extension), or you may create your own environment with the same dependencies.

Dependencies

Install development dependencies with:

pip install .[tests]

Tests

Run tests with:

pytest

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

deflatable-dict-0.3.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

deflatable_dict-0.3.0-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file deflatable-dict-0.3.0.tar.gz.

File metadata

  • Download URL: deflatable-dict-0.3.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.15

File hashes

Hashes for deflatable-dict-0.3.0.tar.gz
Algorithm Hash digest
SHA256 c6536bbf1c6c61f18c96766913a5155043f98a97f300557b5a86e2fc9c80660b
MD5 94eb4cfceafba2c99b5ae73a74075b56
BLAKE2b-256 61b1040fff93ccbcdf396c3d8867f5cbd9a196e7f6ab43a24c66cf99ea9f8cc9

See more details on using hashes here.

File details

Details for the file deflatable_dict-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: deflatable_dict-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.15

File hashes

Hashes for deflatable_dict-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 67aeb4fe2c62b8669d0429007ce01bc38b7582d9c62a751b42bdde6a8f562591
MD5 6c9d092d5d4942ea26b5c218d75b86fa
BLAKE2b-256 301ff7093309c1c5c431abe3b89bd382e6629d095e9b36c96c630444357c598f

See more details on using hashes here.

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