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.1.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

tosql-0.1.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tosql-0.1.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for tosql-0.1.0.tar.gz
Algorithm Hash digest
SHA256 de32ed89f3582305bdd49359ffe09bc28ebad306001f855228aeefd36c9f9cef
MD5 3e84f3b88f0f6f856bf9b0840354015c
BLAKE2b-256 632cf44d0cef8f9d3acc30925349f67a5d1969f15bfa0a7b009c30bb3969bcac

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tosql-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for tosql-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 713d46d8648dba91255557222ba70dd443afa94ffe7f23b263b40d38574f3418
MD5 82a173bd54cdacc1619d04c63e385e71
BLAKE2b-256 d270514d5d5f1455ac15d9e253ddda070456b889b67e52868fac681b01736f70

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page