Skip to main content

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

tosql-0.2.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

tosql-0.2.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file tosql-0.2.0.tar.gz.

File metadata

  • Download URL: tosql-0.2.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.9

File hashes

Hashes for tosql-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4376b8506fef0aefe0789855f972c061b4b1346d307c94b9c5ebcc48a4ec38aa
MD5 a9518f755117c266c9662380078408cc
BLAKE2b-256 5a1c47dec34b1c524d9c902d240e5a9ff34e422a23c33e90c7ba2fd628189d5a

See more details on using hashes here.

File details

Details for the file tosql-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: tosql-0.2.0-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

Hashes for tosql-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eb1d2e862323bbfb3201d4bce07e12875eff922c10786d34adbf1f07322d6ec1
MD5 64fb04777860e5a2eac1217957f5b3ee
BLAKE2b-256 a2a8e907b4f585106020105fdd443306c9721b2c2cf4cd1d4bba399e6311fa3e

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