sqladaptor
Transferring data, stored as JSON or Pandas, into an SQL database and back again.
Why?
Building webserver prototypes, one often saves initial data as JSON or Pandas files. Later, you will want to transition to an SQL database where updating/inserting data to disk is more efficient.
SqlAdaptor allows an easy transition for this transition, using a familiar API consisting of dict lists and pandas dataframes. Table schema are treated as Json-Schema.
This is possible because there is an equivalence between JSON dict lists, Pandas DataFrames and SQL tables - they are all tabular arrangements of columnar data.
Installation
pip install sqladaptor
Basic Usage
Inserting dict lists into an SQLite db
from sqladaptor.sqlite import SqliteAdaptor
import pandas
db = SqliteAdaptor('db.sqlite')
entries = [
{"description": "this", "value": 1},
{"description": "that", "value": 2}
]
db.set_from_df('data1', pandas.DataFrame(entries))
Read as dict lists or dataframes:
entries = db.read_dicts('data1')
# [
# {'description': 'this', 'value': 1},
# {'description': 'that', 'value': 2}
# ]
df = db.read_df("data1", {"value": 2})
# description value
# 0 this 1
# 1 that 2
Get the table schema as Json-schema:
schema = db.read_table_schema("data1")
# {
# │ 'type': 'object',
# │ 'properties': {
# │ │ 'description': {'type': 'string'},
# │ │ 'value': {'type': 'integer'}
# │ },
# │ 'additionalProperties': False
# }
Make an SQL table with Json-schema:
db.create_table(
"data1",
{
"type": "object",
"properties": {
"row_id": {"type": "string"},
"description": {"type": "string"},
"value": {"type": "integer"},
},
"required": ["row_id"],
},
)
Find using dict search:
return_entries = db.read_dicts('data1', {"description": "this"})
# [{'description': 'this', 'value': 1}]
CRUD your database:
db.insert("data1", {"value": 3, "description": "inserted"})
entries = db.read_dicts('data1')
# [
# │ {'description': 'this', 'value': 1},
# │ {'description': 'that', 'value': 2},
# │ {'description': 'inserted', 'value': 3}
# ]
db.update(
"data1",
{"description": "inserted"},
{"description": "inserted-then-updated", "value": 77},
)
entries = db.read_dicts('data1')
# [
# │ {'description': 'this', 'value': 1},
# │ {'description': 'that', 'value': 2},
# │ {'description': 'inserted-then-updated', 'value': 77}
# ]
db.delete("data1", {"value": 77})
entries = db.read_dicts('data1')
# [{'description': 'this', 'value': 1}, {'description': 'that', 'value': 2}]
Metadata
Release files for sqladaptor 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sqladaptor-0.5.0.tar.gz | 9.3 kB | Without provenance | Details for sqladaptor-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sqladaptor-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for sqladaptor-0.5.0-py3-none-any.whl |
Total release size: 14.8 kB
Release files / sqladaptor-0.5.0.tar.gz
| Download URL | sqladaptor-0.5.0.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
35ca7cd7e6b2043b60c83aaf57118086aefa4a1ccea482e3c53cdcb03ce03e5c
|
|
BLAKE2b-256 checksum How to use checksums |
8b096fda003d3805b59a760956a8294899fc6d81f2fb8a02dc55964278c03a5f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.12.3
|
Release files / sqladaptor-0.5.0-py3-none-any.whl
| Download URL | sqladaptor-0.5.0-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aa2c56ac7a4e52a99484cff659ce8274857a49696fd30154a7dbd82a37572b1c
|
|
BLAKE2b-256 checksum How to use checksums |
abfa011ba9d82bf1fbafc4a42929f42ce665a4940aa396810ad8f7c61e85162b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.12.3
|
Security for sqladaptor 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.