Skip to main content

Simple library to make your dictionary flatten

Project description

MakeFlatt

Simple library to make your dictionary flatten in Python

PyPI version PyPI - Python Version Unit Tests Code Style PyPI - License

Installation

pip install makeflatt

Usage

Quick start:

>>> from makeflatt import FlattMaker
>>> mf = FlattMaker()
>>> mf.apply({"a": {"b": {"c": "test"}}})
{'a.b.c': 'test'}

Make nested structured flatten:

>>> mf.apply({"a": {"b": ["b1", "b2", "b3"]}})
{'a.b.0': 'b1', 'a.b.1': 'b2', 'a.b.2': 'b3'}

If you don't wan't to expand nested lists you can set include_lists to False:

>>> mf.apply({"a": {"b": ["b1", "b2", "b3"]}}, include_lists=False)
{'a.b': ['b1', 'b2', 'b3']}

You can also change the separator and define your own:

>>> mf = FlattMaker(sep=":")
>>> mf.apply({"a": {"b": ["b1", "b2", "b3"]}})
{'a:b:0': 'b1', 'a:b:1': 'b2', 'a:b:2': 'b3'}

License

MakeFlatt is released under the MIT Licence. See the bundled LICENSE file for details.

Development

Check the CONTRIBUTING file.

Versioning

This package attempts to use semantic versioning. API changes are indicated by the major version, non-breaking improvements by the minor, and bug fixes in the revision.

It is recommended that you pin your targets to greater or equal to the current version and less than the next major version.

Maintainer

Created and maitained by Jonathan Schweder (@jaswdr)

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

makeflatt-1.0.4.tar.gz (3.4 kB view hashes)

Uploaded Source

Built Distribution

makeflatt-1.0.4-py3-none-any.whl (3.5 kB view hashes)

Uploaded Python 3

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