Skip to main content

preprocesses SQL queries to make them modular

Project description


Build Status Coverage Status

querypp preprocesses SQL queries[1] in order to allow conditional inclusion at runtime. It also includes a loader which loads many queries from a file, delimited by -- :name query_name lines.

[1] Although it is trivially adapted to other languages with line comments, as the only SQL-specific assumption is the comment syntax.

Take an example:

FROM users
-- :block profiles
LEFT JOIN profiles USING (user_id)
-- :block login_history
LEFT JOIN login_history USING (profile_id)
-- :endblock
-- :endblock
-- :block user_id WHERE user_id = $1

A Query object can be called:

  • with no block names to return the entire query
  • with one or more block names to return the query with only those block names.

In this case, q('profiles', 'user_id') would return the query with the login_history JOIN removed.


After moving all my SQL queries to separate files (using the load_sql function), I noticed that I was duplicating some of them except for one extra clause. I created this to allow me to deduplicate such queries.


Public domain, see COPYING

Project details

Download files

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

Files for querypp, version 0.0.3
Filename, size File type Python version Upload date Hashes
Filename, size querypp-0.0.3-py3-none-any.whl (7.4 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size querypp-0.0.3.tar.gz (4.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page