Skip to main content

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
  • 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 yet recommended for use in production.

tests

Learn More

Get started

Simply install via pip:

    pip install -U preql

Then just run the interpreter:

    preql

Requires Python 3.6+

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.

Interactive Environment

Screenshot.png

License

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

See: LICENSE

In simple words, it's free for personal use. Also, 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. Read more

Metadata

Release files for preql 0.2.19

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

Source distribution (sdist)

Source distribution for preql 0.2.19
File Size Uploaded
preql-0.2.19.tar.gz 96.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for preql 0.2.19
File Interpreter ABI Platform
preql-0.2.19-py3-none-any.whl Python 3 none any Details

Total release size: 205.6 kB

Release files / preql-0.2.19.tar.gz

Download URL preql-0.2.19.tar.gz
Size 96.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c981ef074c95b57fa87549108d6f68eb1344ee8068b0be3fef49b0763ffcc0d6
BLAKE2b-256 checksum
How to use checksums
f835bf64ed7423fa5f791a17fadaa8e80edac4e3af4c0fd2e14cb976740a873e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.10.0 Windows/10

Release files / preql-0.2.19-py3-none-any.whl

Download URL preql-0.2.19-py3-none-any.whl
Size 109.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
626c9455cadb6b6871a83496e3d6fa997d69ec819243aac06092f848d7dcb441
BLAKE2b-256 checksum
How to use checksums
d1e77c5ee333ae6bd492f67a20475dc17295876b61dc9c52a9e178b02465e061
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.10.0 Windows/10

Release history Release notifications | RSS feed

This release

0.2.19 This release

2 release files

0.2.18

2 release files

0.2.17

2 release files

0.2.16

2 release files

0.2.15

2 release files

0.2.14

2 release files

0.2.13

2 release files

0.2.12

2 release files

0.2.11

2 release files

0.2.10

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

1 release file

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

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