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.1.tar.gz (15.3 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.1-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dict2rel-0.0.1.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for dict2rel-0.0.1.tar.gz
Algorithm Hash digest
SHA256 6677cbe38bbf6063808dfb6be6e2627528d70e10ab9a53ade97808cabb839cb1
MD5 52324039a16bc11809d691b38ec4f0e0
BLAKE2b-256 8bcb443afbf16f8dd6bccf6ee83e526b75633d1d9f714d8d54fe41b9e582c7e9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dict2rel-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for dict2rel-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5d800c8e703b98ab5f1a811a6c15ba350de30eae3ae9a59dc64f9e7151e4f7d7
MD5 fcb747db9cd3cff8d109ec8ce2576c86
BLAKE2b-256 24f7fd65578d9fd388f4284ef8ba721b32d797dbbd3bee6c3baf54b411a24790

See more details on using hashes here.

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