Skip to main content

Json2DB

Python3.6+

Just need defined a json object, then you can save it in to a relational DB like MySQL PostgreSQL or other DB.

Reason To Write This FrameWork

Although NoSQL Database like MongoDB is popular, we still need SQL DataBase for analyze data, so this module is helping us store json to database, and help us build them in db.

Feature

  • support mostly common database (MySQL, PostgreSQL, MSSQL, SQLite),

just set database like

JFactory(database='mysql')

See more in types

You can set str2col control Database Column Type like Text or VARCHAR and other.You can see more example in tests/test_comom_factory.py

  • Support Different Style of database column

If you want your db column like some_thing style

from json2db import JFactory, ColumnFormat
JFactory(column_fmt=ColumnFormat.UNDERLINE)

If you want your db column to be someThing style, use ColumnFormat.CAMEL

Default we do nothing as the json format.

  • Support Add a TimeStamp for your first table

  • Support set table args for your each table init

  • Support add comment to your field

Just Use {"field": {":my comment": "real value"}}, it can take the my comment to this field

  • Support Control the max_depth of your json table

PS: min is 0 which meaning it only one table for all json

  • Support Restore your data to anther table

if your data like d = {"father_id": 1, "father_name": "father", "brother": {"brother_name": "jack"}, 'sons': [{"son_name": "aa"}}, You can save it to a new table like father - son framework like {"father_id": 1, "brother_name": "jack", 'sons': [{"son_name": "aa", "father_name": "father"}]}

PS: you move brother field to father table, and move father field to son table,you can use

model.store(data=new_d, is_press=True)

See more sample please see tests

A Simple Example

For create_table ,store data and search data

from json2db import JFactory, ColumnFormat
d = {"aa": 1, "bb": 2, "brother": {"name": "jack", "namess": [{"other": "jack"}]}, 'sons': [{"son_name": "aa"}]}

factory = JFactory()
model = factory.from_json(data=d, root_name="data")
model.create_tables_in_db()
model.store(data=d)
model.search(search_args=[("aa", 1)], limit=2)

You can save your data to any sqlalchemy support database like MySQL, PostgreSQL,Oracle,SQLite(Default stored if you not set db_url) and so on. The db_url format please see more detail see https://docs.sqlalchemy.org/en/latest/core/engines.html

Release files for json2db 3.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for json2db 3.2.3
File Size Uploaded
json2db-3.2.3.tar.gz 13.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for json2db 3.2.3
File Interpreter ABI Platform
json2db-3.2.3-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 27.8 kB

Release files / json2db-3.2.3.tar.gz

Download URL json2db-3.2.3.tar.gz
Size 13.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f2c378bb2c41dfab27f9ec00e016156ea5f74bb98dd66cd6cfe21b9fc707cb11
BLAKE2b-256 checksum
How to use checksums
50b2f1496d199ce5b7cd3d2224f8d9c7e121e9f8c42ef68b7a7f2cb2eff9592f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.4

Release files / json2db-3.2.3-py2.py3-none-any.whl

Download URL json2db-3.2.3-py2.py3-none-any.whl
Size 14.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
f8565ea3b90e05ae07d917af6b42cf1bc1c746ee761c01d04d03156111f28df0
BLAKE2b-256 checksum
How to use checksums
d58e2298f7e0df5f518620026a7873bc9fc66e5d536ba6673df6ac304386ca07
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.4

Release history Release notifications | RSS feed

This release

3.2.3 This release

2 release files

3.2.2

2 release files

3.2.1

2 release files

3.1.2

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.0.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page