Package to convert JSON data in SQL table.
Project description
Maceió
Package to insert JSON data into a SQL database.
What it does
In short, given a JSON input, Maceio is able to:
- Create, and populate, a new table based on a JSON input (no need to specify its structure)
- Feed JSON records into an existing table (inserting a new register or updating existing ones)
Getting Started
1. No structure, no db options (quick option)
from Maceio.Maceio import Maceio
if __name__ == "__main__":
# You can use only one dictionary without lists
data = '''[
{
"field1":{
"subfield1": 1,
"subfield2": "TYPE1",
"subfield3":{
"sub1":"Value 1",
"sub2":"Value 2",
}
}
},
{
"field1":{
"subfield1": 2,
"subfield2": "TYPE1",
"subfield3":{
"sub1":"Value 3",
"sub2":"Value 4",
}
}
}
]
''')
maceio = Maceio('postgresql+psycopg2://user:password@host:port/database', 'schema_example')
maceio.save('table_example', data, conflicts=('subfield1', 'subfield2'))
2. Adding db options (connection limits and pool size)
from Maceio.Maceio import Maceio
if __name__ == "__main__":
# You can use only one dictionary without lists
data = '''[
{
"field1":{
"subfield1": 1,
"subfield2": "TYPE1",
"subfield3":{
"sub1":"Value 1",
"sub2":"Value 2",
}
}
},
{
"field1":{
"subfield1": 2,
"subfield2": "TYPE1",
"subfield3":{
"sub1":"Value 3",
"sub2":"Value 4",
}
}
}
]
''')
maceio = Maceio('postgresql+psycopg2://user:password@host:port/database', 'schema_example', pool_size=5, max_overflow=2)
maceio.save('table_example', data, conflicts=('subfield1', 'subfield2'))
3. Disabling table existence check
from Maceio.Maceio import Maceio
if __name__ == "__main__":
# You can use only one dictionary without lists
data = '''[
{
"field1":{
"subfield1": 1,
"subfield2": "TYPE1",
"subfield3":{
"sub1":"Value 1",
"sub2":"Value 2",
}
}
},
{
"field1":{
"subfield1": 2,
"subfield2": "TYPE1",
"subfield3":{
"sub1":"Value 3",
"sub2":"Value 4",
}
}
}
]
''')
maceio = Maceio('postgresql+psycopg2://user:password@host:port/database', 'schema_example', pool_size=5, max_overflow=2)
# To not check if table exists, set verify=False
maceio.save('table_example', data, conflicts=('subfield1', 'subfield2'), verify=False, primaries=('id',))
Disabling JSON format
from Maceio.Maceio import Maceio
if __name__ == "__main__":
# You can use only one dictionary without lists
data = '''[
{
"field1":{
"subfield1": 1,
"subfield2": "TYPE1",
"subfield3":{
"sub1":"Value 1",
"sub2":"Value 2",
}
}
},
{
"field1":{
"subfield1": 2,
"subfield2": "TYPE1",
"subfield3":{
"sub1":"Value 3",
"sub2":"Value 4",
}
}
}
]
''')
# Passing enableJsonType=False disables storing with JSON type, so JSON data will be saved as string instead
maceio = Maceio('postgresql+psycopg2://user:password@host:port/database', 'schema_example', pool_size=5, max_overflow=2, enableJsonType=False)
maceio.save('table_example', data, conflicts=('subfield1', 'subfield2'), verify=True, primaries=('id',))
Saving all data types as string instead
This can be particularly useful for initial exploration of data with unknown data types.
from Maceio.Maceio import Maceio
if __name__ == "__main__":
# You can use only one dictionary without lists
data = '''[
{
"field1":{
"subfield1": 1,
"subfield2": "TYPE1",
"subfield3":{
"sub1":"Value 1",
"sub2":"Value 2",
}
}
},
{
"field1":{
"subfield1": 2,
"subfield2": "TYPE1",
"subfield3":{
"sub1":"Value 3",
"sub2":"Value 4",
}
}
}
]
''')
# To save all formats as string, pass onlyText=True
maceio = Maceio('postgresql+psycopg2://user:password@host:port/database', 'schema_example', pool_size=5, max_overflow=2, onlyText=True)
maceio.save('table_example', data, conflicts=('subfield1', 'subfield2'), verify=True, primaries=('id',))
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
Maceio-1.0.7.tar.gz
(6.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file Maceio-1.0.7.tar.gz.
File metadata
- Download URL: Maceio-1.0.7.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a742cfa85cb196e242bf5090bc4c0f884565fc376f4876102e6980f348ef444
|
|
| MD5 |
68e8740b63b87b4ad17bc386abdd54d2
|
|
| BLAKE2b-256 |
b15005ba5364c4a5a28ef17e71679b6195ce1357a454bf9a53ada72000dcbba4
|
File details
Details for the file Maceio-1.0.7-py3-none-any.whl.
File metadata
- Download URL: Maceio-1.0.7-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb128dbd03cce8b3dd2dd515175968ec26633e2768a717f22ef75e081677fc40
|
|
| MD5 |
48de56d5e80e9a731fc99bee648149cd
|
|
| BLAKE2b-256 |
5a1a58cd5c68dea2f5738e364f39bc7a1ae569adfca4608ac1138033af157b02
|