#polars #sql-query #interface #command-line-interface #running #back-end #cli-interface

app polars-cli

CLI interface for running SQL queries with Polars as backend

8 releases (breaking)

0.7.0 Mar 7, 2024
0.6.0 Jan 4, 2024
0.5.1 Nov 4, 2023
0.5.0 Oct 24, 2023
0.1.0 May 8, 2023

#317 in Encoding

Download history 24/week @ 2023-12-29 12/week @ 2024-01-05 12/week @ 2024-02-16 39/week @ 2024-02-23 167/week @ 2024-03-01 71/week @ 2024-03-08 81/week @ 2024-03-15 12/week @ 2024-03-22 22/week @ 2024-03-29 6/week @ 2024-04-05

128 downloads per month

MIT license

34KB
524 lines

Polars CLI

Crates.io PyPI

The Polars command line interface provides a convenient way to execute SQL commands using Polars as a backend.

Installation

The recommended way to install the Polars CLI is by using pip:

pip install polars-cli

This will install a pre-compiled binary and make it available on your path under polars. If you do not have Python available, you can download a suitable binary from the most recent GitHub release.

Alternatively, you can install the Polars CLI using cargo, which will compile the code from scratch:

cargo install --locked polars-cli

Usage

Running polars without any arguments will start an interactive shell in which you can run SQL commands.

$ polars
Polars CLI version 0.4.0
Type .help for help.

>> select * FROM read_csv('examples/datasets/foods.csv');
┌────────────┬──────────┬────────┬──────────┐
 category   ┆ calories ┆ fats_g ┆ sugars_g │
 ---        ┆ ---      ┆ ---    ┆ ---      │
 str        ┆ i64      ┆ f64    ┆ i64      │
╞════════════╪══════════╪════════╪══════════╡
 vegetables ┆ 45       ┆ 0.5    ┆ 2        │
 seafood    ┆ 150      ┆ 5.0    ┆ 0        │
 meat       ┆ 100      ┆ 5.0    ┆ 0        │
 fruit      ┆ 60       ┆ 0.0    ┆ 11       │
 …          ┆ …        ┆ …      ┆ …        │
 seafood    ┆ 200      ┆ 10.0   ┆ 0        │
 seafood    ┆ 200      ┆ 7.0    ┆ 2        │
 fruit      ┆ 60       ┆ 0.0    ┆ 11       │
 meat       ┆ 110      ┆ 7.0    ┆ 0        │
└────────────┴──────────┴────────┴──────────┘

Alternatively, SQL commands can be piped directly into the Polars CLI.

$ echo "SELECT category FROM read_csv('examples/datasets/foods.csv')" | polars
┌────────────┐
 category   │
 ---        │
 str        │
╞════════════╡
 vegetables │
 seafood    │
 meat       │
 fruit      │
 …          │
 seafood    │
 seafood    │
 fruit      │
 meat       │
└────────────┘

Features

When compiling the Polars CLI from source, the following features can be enabled:

Feature Description
default The default feature set that includes all other features.
highlight Provides syntax highlighting
parquet Enables reading and writing of Apache Parquet files.
json Enables reading and writing of JSON files.
ipc Enables reading and writing of IPC/Apache Arrow files

Dependencies

~32–70MB
~1M SLoC