Skip to main content

Declarative, typed query language that compiles to SQL.

Project description

PreQL/Trilogy

pypreql is an experimental implementation of the PreQL/Trilogy (prequel trilogy) language, a variant on SQL intended to embrace the best features of SQL while fixing common pain points.

Preql looks like SQL, but doesn't require table references, group by, or joins. It's crafted by data professionals to be more human-readable and less error-prone than SQL, and is perfect for a modern data company that just can't quit SQL but wants less pain, including compatability with common tools such as DBT through a rich extension ecosystem.

The Preql language spec itself will be linked from the above repo.

Pypreql can be run locally to parse and execute preql [.preql] models.

You can try out an interactive demo here.

Preql looks like this:

SELECT
    name,
    name_count.sum
WHERE 
    name like '%elvis%'
ORDER BY
    name_count.sum desc
LIMIT 10;

More Examples

Examples can be found in the public model repository. This is a good place to start for a basic understanding of the language.

Backends

The current Preql implementation supports compiling to 3 backend SQL flavors:

  • Bigquery
  • SQL Server
  • DuckDB

Basic Example

Preql can be run directly in python.

A bigquery example, similar to the quickstart

from preql import Dialects, Environment

environment = Environment()

environment.parse('''

key name string;
key gender string;
key state string;
key year int;
key name_count int;
auto name_count.sum <- sum(name_count);

datasource usa_names(
    name:name,
    number:name_count,
    year:year,
    gender:gender,
    state:state
)
address bigquery-public-data.usa_names.usa_1910_2013;

'''
)
executor = Dialects.BIGQUERY.default_executor(environment=environment)

results = executor.execute_text(
'''SELECT
    name,
    name_count.sum
ORDER BY
    name_count.sum desc
LIMIT 10;
'''

)
# multiple queries can result from one text batch
for row in results:
    # get results for first query
    answers = row.fetchall()
    for x in answers:
        print(x)

Developing

Clone repository and install requirements

Contributing

Please open an issue first to discuss what you would like to change, and then create a PR against that issue.

Similar in space

  • singleorigin
  • malloy

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pypreql-0.0.1rc80.tar.gz (79.5 kB view hashes)

Uploaded Source

Built Distribution

pypreql-0.0.1rc80-py3-none-any.whl (92.7 kB view hashes)

Uploaded Python 3

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