Skip to main content

LocalSQL is for querying local csv, xlsx, json files using SQL.

If you like the idea of pipeliner click ⭐ on the repo and stay tuned.

Install

pip install git+https://github.com/localsql/localsql

Usage

$ lsql --help
usage: lsql [-h] [-d DIRECTORY] [-r] [-q QUERY] [-v] [-s] [-jn] [--version] [files [files ...]]

Querying local files using SQL.

positional arguments:
  files                 Files with tables: csv, xlsx, json.

optional arguments:
  -h, --help            show this help message and exit
  -d DIRECTORY, --directory DIRECTORY
                        Search files in this directory.
  -r, --recursive       Search files in the directory and subdirectories.
  -q QUERY, --query QUERY
                        Run SQL query and return result.
  -v, --verbose         Verbose mode.
  -s, --silent          Silent mode.
  -jn, --json-normalize
                        JSON normalize.
  --version, -V         show program's version number and exit

SQL syntax

LocalSQL uses SQLite syntax.

Use cases

To repeat the use cases get the repository:

$ cd ~ && git clone --depth 1 https://github.com/localsql/localsql && cd localsql
$ lsql -d examples
examples/one.json: table=one_json, columns=4, rows=3
examples/lines.json: table=lines_json, columns=3, rows=3
examples/nested.json: table=nested_json, columns=5, rows=3
examples/excel.xlsx: table=excel_xlsx, columns=3, rows=5
examples/csv.csv: table=csv_csv, columns=3, rows=3
lsql>

Interactive

lsql> select * from excel_xlsx
   id   b   c
0   1   6  11
1   2   7  12
2   3   8  13
3   4   9  14
4   5  10  15

lsql> SELECT * FROM excel_xlsx e LEFT JOIN one_json j ON e.id = j.id
   id   b   c   id    b    c    d
0   1   6  11  1.0  4.0  NaN  NaN
1   2   7  12  2.0  NaN  5.0  NaN
2   3   8  13  3.0  NaN  NaN  6.0
3   4   9  14  NaN  NaN  NaN  NaN
4   5  10  15  NaN  NaN  NaN  NaN

Not interactive

$ lsql -d examples -q "SELECT c, count(*) as cnt FROM one_json GROUP BY c ORDER BY 1 ASC NULLS LAST" -s
     c  cnt
0  5.0    1
1  NaN    2

Transpose output

To transpose the output add /t to the end of query:

lsql> SELECT * FROM nested_json LIMIT 1 /t
id                1
nest.a            1
nest.b    [1, 2, 3]
nest           None
c              None
Name: 0, dtype: object

Python mode

lsql> \lpy
lpy> print(self.tables['csv_csv'])
   id  b  c
0   1  4  7
1   2  5  8
2   3  6  9

Pretty print

lsql> \pp
Pretty print ON
lsql> select * from one_json
╭─────┬─────┬─────┬─────╮
│  id │   b │   c │   d │
├─────┼─────┼─────┼─────┤
│   1 │   4 │ nan │ nan │
│   2 │ nan │   5 │ nan │
│   3 │ nan │ nan │   6 │
╰─────┴─────┴─────┴─────╯

Metadata

Release files for localsql 0.2.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for localsql 0.2.5
File Size Uploaded Provenance Actions
localsql-0.2.5.tar.gz 7.3 kB Without provenance Details for localsql-0.2.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for localsql 0.2.5
File Interpreter ABI Platform Actions
localsql-0.2.5-py3-none-any.whl Python 3 none any Details for localsql-0.2.5-py3-none-any.whl

Total release size: 14.9 kB

Release files / localsql-0.2.5.tar.gz

Download URL localsql-0.2.5.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f576cb359b5b4b8cfaed644b39de304535ac6e01ce8631b1ec9d07985284c4d1
BLAKE2b-256 checksum
How to use checksums
a7c317aafa9c7a47d3c93d28fb4a9d1d4bd5150ca28e56434dd536d015292a57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

Release files / localsql-0.2.5-py3-none-any.whl

Download URL localsql-0.2.5-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
343145d0d54ffb263d955a420b9985829285967a631cf2b12b0d89f391793554
BLAKE2b-256 checksum
How to use checksums
03f1d3f2a4a12307d8d1391a1f0e7bc14e72c02400a59e80ba76da4336823ef0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

Security for localsql 0.2.5

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page