Skip to main content

No project description provided

Project description

dict2rel

PyPI - Version PyPI - Python Version codecov

dict2rel is a Python library which can transform JSON with any level of nesting into one or more tables which contain enough information that the tables can be modified and then converted back to the nested JSON format. Essentially, JSON can be converted to relational tables and then back.


Table of Contents

Installation

pip install dict2rel

Quick Start

from dict2rel import dict2rel
import pandas as pd  # you can also use polars.DataFrame

tables = dict2rel(
    [
        {
            "name": "relay-settings",
            "version": {
                "major": 1,
                "minor": 12,
                "patch": 1
            },
            "settings": [
                {
                    "key": "tempo",
                    "value": 12
                },
                {
                    "key": "delay",
                    "value": 14
                }
            ]
        },
        {
            "name": "response-settings",
            "version": {
                "major": 12,
                "minor": 0,
                "patch": 3
            },
            "settings": [
                {
                    "key": "throttle",
                    "value": "always"
                },
                {
                    "key": "burst",
                    "value": 0.43
                }
            ]
        },
    ],
    pd.DataFrame  # the tables will be of this type
)

tables will end up being a dict of the following tables:

*

name version.major version.minor version.patch _id
relay-settings 1 12 1 0
response-settings 12 0 3 1

*.settings

key value _id
tempo 12 0.settings.0
delay 14 0.settings.1
throttle always 1.settings.0
burst 0.43 1.settings.1

These tables can then be modified, maybe by adding a new column:

tables["*.settings"]["added"] = ["2025-12-18"] * len(tables["*.settings"])

and then converted back to nested JSON:

from dict2rel import rel2dict

transformed_data = rel2dict(tables)

which gives the following JSON:

[
    {
        "name": "relay-settings", 
        "version": {"major": 1, "minor": 12, "patch": 1}, 
        "settings": [
            {"key": "tempo", "value": 12, "added": "2025-12-18"}, 
            {"key": "delay", "value": 14, "added": "2025-12-18"}
        ]
    }, 
    {
        "name": "response-settings", 
        "version": {"major": 12, "minor": 0, "patch": 3}, 
        "settings": [
            {"key": "throttle", "value": "always", "added": "2025-12-18"}, 
            {"key": "burst", "value": 0.43, "added": "2025-12-18"}
        ]
    }
]

License

dict2rel is distributed under the terms of the MIT license.

Development

Make sure to run hatch fmt, hatch run black:run, hatch run test:run, and hatch run docs:build.

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

dict2rel-0.0.2.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dict2rel-0.0.2-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file dict2rel-0.0.2.tar.gz.

File metadata

  • Download URL: dict2rel-0.0.2.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dict2rel-0.0.2.tar.gz
Algorithm Hash digest
SHA256 887e0496cd1071dfea68a914758e0631494c373eec81992afb54e251ea319222
MD5 6c5e9f0f8f6b2d37d3fd6e8a6a5ca2a2
BLAKE2b-256 0b21344660d36dcd770542c4aa43abf17c143ae552f52ac49607a89353f849c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for dict2rel-0.0.2.tar.gz:

Publisher: publish.yml on BlendingJake/Dict2Rel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dict2rel-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: dict2rel-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dict2rel-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 608b7481b2a05c79e6cac70a97fc86a73b71c3fd299d3ddff82bd9bc18e5bf07
MD5 b88968e32d385454f33c3f8d953bc56a
BLAKE2b-256 3d71fd4a4aa49b08ae1ec6fb575b55d69ee51909e6e85d58959b920534ad5a24

See more details on using hashes here.

Provenance

The following attestation bundles were made for dict2rel-0.0.2-py3-none-any.whl:

Publisher: publish.yml on BlendingJake/Dict2Rel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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