Skip to main content
File added late

1 file was added to this release more than 14 days after its initial publication. Inspect the release files before installing.

sqloose is a SQL-like query language that maps directly to SQL. This module does not implement a database itself, but is instead a translator from sqloose to SQL.

Installation

pip install python-sqloose

Usage

from sqloose import sqloose

sql = sqloose.to_sql("SELECT age, race, gender, count(*) AS num FROM stats GROUP BY [1:3] ORDER BY -1 DESC")

Use Case

sqloose is designed as a less rigid SQL, offering a more convenient syntax. In particular, it allows ranges and negative indices to be used in GROUP BY and ORDER BY statements. The right index in the range specifies the final item, unlike Python in which the right index is the final item + 1.

Take the following SQL statement:

SELECT age, race, gender, count(*) AS num FROM stats GROUP BY 1,2,3 ORDER BY 4 DESC

In sqloose this can be represented many ways, such as:

SELECT age, race, gender, count(*) AS num FROM stats GROUP BY [1:3] ORDER BY -1 DESC
SELECT age, race, gender, count(*) AS num FROM stats GROUP BY [:3] ORDER BY -1 DESC
SELECT age, race, gender, count(*) AS num FROM stats GROUP BY [:-2] ORDER BY -1 DESC

Further, sqloose defines the GROUP TO and GROUP THROUGH constructs, which can be used in the same scenario:

SELECT age, race, gender, count(*) AS num FROM stats GROUP TO -1 ORDER BY -1 DESC
SELECT age, race, gender, count(*) AS num FROM stats GROUP TO 4 ORDER BY -1 DESC
SELECT age, race, gender, count(*) AS num FROM stats GROUP THROUGH 3 ORDER BY -1 DESC

SQL is often used in an interactive fashion, where data is being explored rather than simply being gathered. Queries are discovered, rather than being innately known. The pattern usually involves looking at aggregates (counts, sums, means), while changing both the selection of columns and the depth to find the most meaningful insights. The frustration in using this pattern is that we often must change the start of the query (the column list) and also the near end (the grouping indices). This can be made largely unnecessary by expanding SQL syntax to be more expressive.

sqloose does not validate the correctness of your SQL, but does validate the correctness of the constructs that are specific to sqloose, including the ranges and use of GROUP TO and GROUP THROUGH.

Authors

rdj - https://oddacious.github.io

History

0.1.0a1 (2016-09-25)

  • First pre-release on Github.

Release files for sqloose 0.1.0

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

File added late

1 file was uploaded more than 14 days after the first file in this release.

While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.

We recommend inspecting the release files before installing.

Source distribution (sdist)

Source distribution for sqloose 0.1.0
File Size Uploaded
sqloose-0.1.0.tar.gz 24.6 kB Details

Release files / sqloose-0.1.0.tar.gz

File added late

This file was uploaded more than 14 days after the first file in this release.

While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.

We recommend inspecting the release file before installing.

Download URL sqloose-0.1.0.tar.gz
Size 24.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d404af4a344dd3abd5b6e7a27ad175a2086de7cfbf53f76adf619d14eef3a9c4
BLAKE2b-256 checksum
How to use checksums
c2364705a4ad422cb070c14c70705413cb730a685274c5af1ccd20a059e91ea3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file

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