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 JSON dict lists, 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.read_dicts('data1')
# [
#   {'description': 'this', 'value': 1}, 
#   {'description': 'that', 'value': 2}
# ]

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

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

db.update("data1", {"value": 2}, {"description": "altered"})
return_entries2 = db.read_dicts('data1', {"value": 2})
# [{'description': 'altered', 'value': 2}]

The API

The key idea is to provide a JSON-like API for an SQL database. This will get provide a simple way of moving JSON lists into a database. With the API, JSON lists are easily returned. This is to simplify the transition of a good prototype into a production database.

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.4.tar.gz (9.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.4-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sqladaptor-0.4.tar.gz
  • Upload date:
  • Size: 9.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.4.tar.gz
Algorithm Hash digest
SHA256 022ae404ef9b30160747bc75d6541ec472c9ae0767153867e39b750238fa00ef
MD5 c65365f682d5d3b1e56a85d2034a42f2
BLAKE2b-256 f759a7303fda48f42c7371304e301034a4afdbf3063c43e9c2d06dc8ed43c219

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqladaptor-0.4-py3-none-any.whl
  • Upload date:
  • Size: 5.2 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 68cf1bf6c1db63aca5c6e1d3e1b854c9a8353abfb33693a808cdbd30f58ee2fd
MD5 dccfb228c3c3bf8d6fe4622b8e96a9f0
BLAKE2b-256 2196d9d440832ba507be8fa7fc3bee4a6ed18d6d57deed0e8396d7eed03256a4

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