Skip to main content

Starting adaptor for JSON/Pandas to SQL db

Project description

sqladaptor

Transferring data, stored as JSON or Pandas, into an SQL database and back again.

Why?

Building webserver protoytpes, you will often save your data as JSON or Pandas files. At some point though, you will want to transition to a database where updating/inserting data to disk is more efficient.

SqlAdaptor allows an easy transition to such a database. This includes methods to search using dicts, and to return rows as dicts for web-servers.

This is possible because there is an equivalence between lists of JSON dicts, Pandas DataFrames and SQl tables - they are all tabular arrangements of columnar data.

Installation

pip install sqladaptor

Basic Usage

from sqladaptor.sqlite import SqliteAdaptor
import pandas

entries = [
    {"description": "this", "value": 1},
    {"description": "that", "value": 2}
]

db = SqliteAdaptor('db.sqlite')
db.set_from_df('data1', pandas.DataFrame(entries))

entries = db.get_dict_list('data1')
# [{'description': 'this', 'value': 1}, {'description': 'that', 'value': 2}]

entries = db.get_dict_list('data1', {"description": "this"})
# [{'description': 'this', 'value': 1}]

df = db.get_df("data1", {"value": 2})
#   description  value
# 0        that      2

db.update("data1", {"value": 2}, {"description": "altered"})
entries = db.get_dict_list('data1', {"value": 2})
[{'description': 'altered', 'value': 2}]

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

sqladaptor-0.1.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

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

sqladaptor-0.1.0-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file sqladaptor-0.1.0.tar.gz.

File metadata

  • Download URL: sqladaptor-0.1.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.3

File hashes

Hashes for sqladaptor-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4930155144c667c4d2144e683ef72010b861e73b8bcc215a5fac4d393e033d28
MD5 8f11422810e3f7899dd0384ef131e904
BLAKE2b-256 5a51f0fe3bc1bdad4358370d678d0db72697be22922aa977a254e2f2657654e5

See more details on using hashes here.

File details

Details for the file sqladaptor-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sqladaptor-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.3

File hashes

Hashes for sqladaptor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 250dd5c09e84cfe3c30bbc13fb7a675f426f52135a84b783b0acaa025a124310
MD5 2890c5e27c8f67f6155443d1f3bb0557
BLAKE2b-256 e4a1710bc2b3111041a2aca3be062c63cd1abea58a247fe5fcd1f0d0a487ef6d

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