tosql - pipe data to sql queries
Project description
tosql - run sql queries on CLI data
tosql is a cli tool for running SQL queries on CLI data and outputting results to json
format. It can read/write from stdin/stdout so it should work fairly naturally.
It can also perform joins for data that comes from multiple input files.
Setup
Install via pip:
pip install tosql
Quick Start
Pipe any tabular data in and use tosql to run a sql query on it. The default table
name to select from is "a"
df | tosql "SELECT * FROM a LIMIT 2"
If you run tosql with no arguments it will "SELECT * FROM a" by default.
df | tosql
Joins
tosql reads multiple input files into tables called a,b,c,... , which you can perform join on.
For example:
# join a csv of daily prices with a json file of sales on different days
tosql -i examples/daily-price.csv -i examples/daily-sells.json "SELECT a.Open as price, b.amount, b.day FROM a JOIN b ON a.Date = b.day LIMIT 10"
# calculate the total sold
tosql -i examples/daily-price.csv -i examples/daily-sells.json "SELECT SUM(Open*amount) FROM a JOIN b ON a.Date = b.day"
CLI Options
tosql has several command line options to choose from, displyed by running with the
"--help" flag.
$ tosql --help
Usage: tosql [OPTIONS] [SQL]
Options:
--version Show the version and exit.
-i, --input FILENAME Input file, default stdin
-o, --output TEXT Output file, default stdout
-f, --sql-file TEXT File containing SQL query
-t, --table-name TEXT Table name [default: df]
-c, --cols TEXT Column names, comma separated
--auto Autogenerate column names: a b c ...
--save Save the sql file to .tosql.db
--help Show this message and exit.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tosql-0.2.1.tar.gz.
File metadata
- Download URL: tosql-0.2.1.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef82e6fa855925634d89cb996025500d760205c459c84c4dbd66237abcc91293
|
|
| MD5 |
9d590148ed7ec9e49e7057c0761e3cf9
|
|
| BLAKE2b-256 |
c8d1c7a8aebd171c51ff3115e244630869080f8bfea9c46009b1b74823908ec2
|
File details
Details for the file tosql-0.2.1-py3-none-any.whl.
File metadata
- Download URL: tosql-0.2.1-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f45273d2ec5ba1c2584d92dd2ee6c4a432095d1d195c90e1c41663f8813cfcc6
|
|
| MD5 |
46072a0ada18ae9a9a3d28f7c1fe2689
|
|
| BLAKE2b-256 |
25b200f86348303d15ec957a1b5d6ee48f556bfc7f67076179694802435f438e
|