Skip to main content

An interpreted relational query language that compiles to SQL

Project description

alt text

Preql (pronounced: Prequel) is an interpreted, relational programming language, that specializes in database queries.

It is designed for use by data engineers, analysts and data scientists.

Preql's main objective is to provide an alternative to SQL, in the form of a high-level programming language, with first-class functions, modules, strict typing, and Python integration.

How does it work?

Preql code is interpreted and gets compiled to SQL at runtime. This way, Preql gains the performance and abilities of SQL, but can also operate as a normal scripting language.

Currently supported dialects are:

  • Postgres
  • MySQL
  • Sqlite
  • BigQuery (soon)
  • More... (planned)

For features that are database-specific, or aren't implemented in Preql, there is a SQL() function that provides a convenient escape hatch to write raw SQL code.

Main Features

  • Modern syntax and semantics
    • Interpreted, everything is an object
    • Strong type system with gradual type validation and duck-typing
  • Compiles to SQL
  • Python and Pandas integration
  • Interactive shell (REPL) with auto-completion
  • Runs on Jupyter Notebook

Note: Preql is still work in progress, and isn't ready for production use, or any serious use quite yet.

Learn More

Get started

Simply install via pip:

    pip install -U preql-lang

Then just run the interpreter:

    preql

Requires Python 3.8+

Read more

Quick Example

// The following code sums up all the squares of an aggregated list of
// numbers, grouped by whether they are odd or even.

func sum_of_squares(x) = sum(x * x)
func is_even(x) = (x % 2 == 0)

// Create a list of [1, 2, 3, ..., 99]
num_list = [1..100]

// Group by is_even(), and run sum_of_squares() on the grouped values.
print num_list{ is_even(item) => sum_of_squares(item) }

// Result is:
┏━━━━━━━━━┳━━━━━━━━┓
 is_even  sqrsum 
┡━━━━━━━━━╇━━━━━━━━┩
       0  166650 
       1  161700 
└─────────┴────────┘

In the background, this was run by executing the following compiled SQL code (reformatted):

  WITH range1 AS (SELECT 1 AS item UNION ALL SELECT item+1 FROM range1 WHERE item+1<100)
  SELECT ((item % 2) = 0) AS is_even, SUM(item * item) AS sqrsum FROM range1 GROUP BY 1;

License

Preql uses an “Interface-Protection Clause” on top of the MIT license.

See: LICENSE

In simple words, it can be used for any commercial or non-commercial purpose, as long as your product doesn't base its value on exposing the Preql language itself to your users.

If you want to add the Preql language interface as a user-facing part of your commercial product, contact us for a commercial license.

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

preql-lang-0.1.19.tar.gz (74.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

preql_lang-0.1.19-py3-none-any.whl (84.5 kB view details)

Uploaded Python 3

File details

Details for the file preql-lang-0.1.19.tar.gz.

File metadata

  • Download URL: preql-lang-0.1.19.tar.gz
  • Upload date:
  • Size: 74.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.2 CPython/3.8.2 Windows/10

File hashes

Hashes for preql-lang-0.1.19.tar.gz
Algorithm Hash digest
SHA256 2bdbbd66a503c514a1b4f9b711617e23b8c13883df424b8d3b34904ced0754cd
MD5 4c06b60b0d3df49857d540369c348cf3
BLAKE2b-256 17098972b4fb834ad278cc80e836b12d13600d1339389f416bda4134dee5bcd7

See more details on using hashes here.

File details

Details for the file preql_lang-0.1.19-py3-none-any.whl.

File metadata

  • Download URL: preql_lang-0.1.19-py3-none-any.whl
  • Upload date:
  • Size: 84.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.2 CPython/3.8.2 Windows/10

File hashes

Hashes for preql_lang-0.1.19-py3-none-any.whl
Algorithm Hash digest
SHA256 f3dc89389508f05e12f54375cd49c69406dd78f2391b66ea87ae58deba74dad5
MD5 3a2c4b683ae2cb5aea0b1d1bedd6519f
BLAKE2b-256 5ec5b6b01d5fa481c1647e79381db6c667e2afeaf5150117a99bcc384fb6f9cc

See more details on using hashes here.

Supported by

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