Skip to main content

ButtercupQL for Python

A Python-like language for SQL, named after the buttercup flower. Write a query the way you write Python, one step per line in the order the data flows; ButtercupQL compiles it to the SQL your database runs, with every value passed as a parameter.

pip install buttercupql
import sqlite3
import buttercupql

db = sqlite3.connect("cases.db")
rows = buttercupql.run(db, """
    from cases
    where status == "open" and band in ["critical", "high"]
    sort -risk
    take 20
""")

run() compiles the text for the database the connection is to, runs it with the database's own driver, and gives the rows, with their columns' names in rows.columns and rows.to_pandas() for a DataFrame. It takes sqlite3, psycopg, psycopg2, pg8000 and duckdb connections, and clickhouse_connect clients. A text that changes the database runs as one transaction: all of it, or none of it if a statement fails.

compile() gives the SQL and its parameters, for any driver:

query = buttercupql.compile('from cases\nwhere status == "open"\n', dialect="sqlite")
rows = db.execute(query.sql, query.params).fetchall()

dialect is sqlite, postgres, duckdb or clickhouse. Each gets its own placeholders: ? for SQLite, $1 for PostgreSQL and DuckDB, and {p1:String} for ClickHouse; params="format" writes psycopg's %s.

In Jupyter and IPython, %load_ext buttercupql gives a cell magic: a cell under %%bcql db runs on the connection db and shows its rows, with its names checked against the database's own tables first.

  • Mistakes are shown at their place, every one at once: buttercupql.CompileError holds them, and its message shows each under its line, with a suggestion.
  • A schema checks every name: schema="CREATE TABLE cases (...)" takes the database's own statements, and buttercupql.read_schema(db) reads them from the database.
  • Changes to the database: update, delete and insert into at the end of a query, create table with Python's annotations, indexes, with transaction:, permissions, recursive queries and pivots.
  • Queries with arguments: compile(text, query="cases_for") compiles a query def with its parameters left as placeholders, and query.bind(account="A1") gives their values.
  • The command comes with the package: bcql compile query.bcql, bcql check *.bcql, and bcql lsp for editors.

The language, its design and its documentation: https://github.com/mkusiappiah/ButtercupQL.

Metadata

Release files for buttercupql 0.2.0

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

Source distribution (sdist)

Source distribution for buttercupql 0.2.0
File Size Uploaded Provenance Actions
buttercupql-0.2.0.tar.gz 232.7 kB Without provenance Details for buttercupql-0.2.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for buttercupql 0.2.0
File Actions
buttercupql-0.2.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for buttercupql-0.2.0-cp39-abi3-win_amd64.whl
buttercupql-0.2.0-cp39-abi3-musllinux_1_2_x86_64.whl CPython 3.9 abi3 Linux musl 1.2+ x86-64 Details for buttercupql-0.2.0-cp39-abi3-musllinux_1_2_x86_64.whl
buttercupql-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details for buttercupql-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
buttercupql-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details for buttercupql-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
buttercupql-0.2.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for buttercupql-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
buttercupql-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for buttercupql-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 6.3 MB

Release files / buttercupql-0.2.0.tar.gz

Download URL buttercupql-0.2.0.tar.gz
Size 232.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7c7783ecb1ad5f59c9f6fa6a95c3baa96c2af2aed7407b2c8ddb327052f4864b
BLAKE2b-256 checksum
How to use checksums
a5843b36a08a9501c61b14466fbbe0857676119f48a288c007fb0ed1dade8bfa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.1

Release files / buttercupql-0.2.0-cp39-abi3-win_amd64.whl

Download URL buttercupql-0.2.0-cp39-abi3-win_amd64.whl
Size 894.2 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
272fd25d48a255797750de13e9ded4d9801fd6bf8454ff13569f558c73b72440
BLAKE2b-256 checksum
How to use checksums
c393147c28533469fb21c169e477b4f205c40c6778befc47c863e98dfd3c476c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.1

Release files / buttercupql-0.2.0-cp39-abi3-musllinux_1_2_x86_64.whl

Download URL buttercupql-0.2.0-cp39-abi3-musllinux_1_2_x86_64.whl
Size 1.2 MB
Tags CPython 3.9 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
7947c84474c1caf55a5f0b73e22fc32fe9d0632bfb89a62e55d29e468b119059
BLAKE2b-256 checksum
How to use checksums
18d29db194fae2cba9733455a9320559d767b84952b4c9dedcdab141b8ba416e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.1

Release files / buttercupql-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL buttercupql-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.0 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
4562ae4cd5406e51bd91c7e3f5a76310ba84d1c7b5cf2aa82c9a263040ca96d8
BLAKE2b-256 checksum
How to use checksums
87bce529ec52b66c8fd22dd624fb1767487196b56a665522265134a0139f37a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.1

Release files / buttercupql-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL buttercupql-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 995.7 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
c5a840cb973977c09dc3107471039403c3ded60d379ad89a885a0bb20cdeb0a9
BLAKE2b-256 checksum
How to use checksums
70a4fde67a13e52f0d21c369782d7ee25f06d075d0356537ebdc2b2206974894
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.1

Release files / buttercupql-0.2.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL buttercupql-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
Size 932.5 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
68fa28c6895603e5f47fdf51f39d4c57d0131b83d6f5ad8d33d0046f1d668833
BLAKE2b-256 checksum
How to use checksums
cda8730af12d3cb92c06450168edbfa2663c92724d403a6de9b5dd8999bdd095
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.1

Release files / buttercupql-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl

Download URL buttercupql-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 954.7 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
3a5f47e9a04a30cf576175a3a15abe28487fe41c281a18cee5c683b99eafdbda
BLAKE2b-256 checksum
How to use checksums
12f632e36b989aafb82ea60c1843d70b55a48e738ff2308baee7ed6ea04d07fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.1

Security for buttercupql 0.2.0

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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

7 release files No provenance

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