Skip to main content

An interpreted relational query language that compiles to SQL

Project description

alt text

Preql 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

// Declare a new table
table Continent {
    name: string
    area: int       // km²
    population: int
}

// Initialize the table, by inserting rows
new Continent("Africa", 30370000, 1287920000)
new Continent("Antarctica", 14000000, 4490)
new Continent("Asia", 44579000, 4545133000)
new Continent("Europe", 10180000, 742648000)
new Continent("North America", 24709000, 587615000)
new Continent("South America", 17840000, 428240000)
new Continent("Australia", 8600000, 41261000)

// Print the continents, ordered by density
print Continent {
    ...                         // Include existing fields
    density: population / area  // Create new a field

} order{^density}

// Print the total land area
print "Total land area:", sum(Continent{area}), "km²"

//  ========================= Output ==========================

                              table  =7
┏━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┓
 id  name               area  population                density 
┡━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━┩
  3  Asia           44579000  4545133000      101.9568182328002 
  4  Europe         10180000   742648000       72.9516699410609 
  1  Africa         30370000  1287920000      42.40763911755021 
  6  South America  17840000   428240000     24.004484304932735 
  5  North America  24709000   587615000     23.781415678497712 
  7  Australia       8600000    41261000      4.797790697674419 
  2  Antarctica     14000000        4490  0.0003207142857142857 
└────┴───────────────┴──────────┴────────────┴───────────────────────┘

Total land area: 150278000 km²

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

-- Continent {..., density: population / area} order{ ^density }
WITH subq_1(id, name, area, population, density) AS (
    SELECT id, name, area, population, (CAST(population AS float) / area) AS density
    FROM Continent
    ORDER BY density DESC)
SELECT * FROM subq_1

See more examples in the examples folder.

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.20.tar.gz (88.8 kB view details)

Uploaded Source

Built Distribution

preql_lang-0.1.20-py3-none-any.whl (99.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: preql-lang-0.1.20.tar.gz
  • Upload date:
  • Size: 88.8 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.20.tar.gz
Algorithm Hash digest
SHA256 d398c7e9c615b23273cc70ef67d6fef32def2d61bff679e164a0d38f7a00286d
MD5 32a6a9726201a7664f9b6df5043cffaa
BLAKE2b-256 a8a075c56ddaf7d903d649526610aef4e92ffda9f6ab7d0f9503001d044c8cc1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: preql_lang-0.1.20-py3-none-any.whl
  • Upload date:
  • Size: 99.4 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.20-py3-none-any.whl
Algorithm Hash digest
SHA256 443efaffece8cd6a7a216c8cd0b53758b14e7b05dff1beb5200efb3b97c3564a
MD5 8960510641a5220e8a6ee9050a5f46e1
BLAKE2b-256 fca4a04a57f58b900c5f587dc65a703daeba73c5fa31b3c806ecfe3aca5bf82d

See more details on using hashes here.

Supported by

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