Skip to main content

run SQL queries on JSON data

Project description

abstra-json-sql

abstra-json-sql is a Python library that allows you to run SQL queries on JSON data. It is designed to be simple and easy to use, while providing powerful features for querying and manipulating JSON data.

Installation

You can install abstra-json-sql using pip:

pip install abstra-json-sql

Usage

Command Line Interface

Assuming you have a directory structure like this:

.
├── organizations.json
├── projects.json
└── users.json

You can query the JSON files using SQL syntax. For example, to get all users from the users file, you can run:

abstra-json-sql "select * from users"

This will return all the users in the users.json file.

Python API

You can also use abstra-json-sql in your Python code. Here's an example:

from abstra_json_sql.eval import eval_sql
from abstra_json_sql.tables import InMemoryTables, Table, Column

code = "\n".join(
    [
        "select foo, count(*)",
        "from bar as baz",
        "where foo is not null",
        "group by foo",
        "having foo <> 2",
        "order by foo",
        "limit 1 offset 1",
    ]
)
tables = InMemoryTables(
    tables=[
        Table(
            name="bar",
            columns=[Column(name="foo", type="text")],
            data=[
                {"foo": 1},
                {"foo": 2},
                {"foo": 3},
                {"foo": 2},
                {"foo": None},
                {"foo": 3},
                {"foo": 1},
            ],
        )
    ],
)
ctx = {}
result = eval_sql(code=code, tables=tables, ctx=ctx)

print(result) # [{"foo": 3, "count": 2}]

Supported SQL Syntax

  • WITH

    • RECURSIVE
  • SELECT

    • ALL
    • DISTINCT
    • *
    • FROM
    • WHERE
    • GROUP BY
    • HAVING
    • WINDOW
    • ORDER BY
    • LIMIT
    • OFFSET
    • FETCH
    • FOR
  • INSERT

  • UPDATE

  • DELETE

  • CREATE

  • DROP

  • ALTER

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

abstra_json_sql-0.0.7.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

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

abstra_json_sql-0.0.7-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file abstra_json_sql-0.0.7.tar.gz.

File metadata

  • Download URL: abstra_json_sql-0.0.7.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for abstra_json_sql-0.0.7.tar.gz
Algorithm Hash digest
SHA256 427a06a7a5b735ed286750a2b8ca84ccd943b0a2648e3794dc5b4434b2706d6d
MD5 f2016a4bf54029d368f06c4c15f194b1
BLAKE2b-256 729d5dbf5b087f48768133cd20a15851716dc3e42f36cd9f2cb421258f21beb8

See more details on using hashes here.

File details

Details for the file abstra_json_sql-0.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for abstra_json_sql-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 0a5c0a07b81bb2c23be43dc10be9316663d98c5ae61ac895b1f559a1e65d4ed6
MD5 cbf781a1e93032ff94a4ec121a2ee3d7
BLAKE2b-256 5991f07112402a18b7c30ad2942a8adde576fa886ebac8b536088da5d25406a8

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