Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

queryparser

Tool for parsing and processing of (MySQL*)/PostgreSQL and translation of ADQL SELECT-like queries

Designed to be used in conjunction with django-daiquri as a query processing backend but it can be easily used as a stand-alone tool or integrated into another project.

*NOTE: Since version 0.7.0 MySQL is not supported (maintained) anymore.

pytest Workflow Status Coverage Status License Latest Version

Installation

The easiest way to install the package is by using the pip tool:

python -m pip install queryparser-python3

Alternatively, you can clone the repository and install it from there. However, this step also requires generating the parser which is a slightly more elaborate process (see below).

Generating the parser from the git repository

To generate the parsers you need python3 , java above version 7, and antlr4 (antlr-4.*-complete.jar has to be installed inside the /usr/local/lib/, /usr/local/bin/ or root directory of the project).

The current version of antlr-4.*-complete.jar can be downloaded via

wget http://www.antlr.org/download/antlr-4.13.1-complete.jar

After cloning the project run

make

and a lib directory will be created. After that, run

python -m pip install .

to install the generated parser in your virtual environment.

Additional requirements

The queryparser assumes that the PostgreSQL database has the extension pg_sphere installed. Although pg_sphere is not required for the Python module, PostgreSQL queries will not run without this extension installed in the database.

Parsing MySQL and PostgreSQL

Since version 0.7, MySQL part of the parser is not maintained anymore. Thus, the MySQL related functionality cannot be guaranteed!

Parsing and processing of MySQL queries can be done by creating an instance of the MySQLQueryProcessor class

from queryparser.mysql import MySQLQueryProcessor
qp = MySQLQueryProcessor()

feeding it a MySQL query

sql = "SELECT a FROM db.tab;"
qp.set_query(sql)

and running it with

qp.process_query()

After the processing is completed, the processor object qp will include tables, columns, functions, and keywords used in the query or will raise a QuerySyntaxError if there are any syntax errors in the query.

Alternatively, passing the query at initialization automatically processes it.

PostgreSQL parsing is very similar to MySQL, except it requires importing the PostgreSQLProcessor class:

from queryparser.postgresql import PostgreSQLQueryProcessor
qp = PostgreSQLQueryProcessor()

The rest of the functionality remains the same.

Translating ADQL

Translation of ADQL queries is done similarly by first creating an instance of the ADQLQueryTranslator class

from queryparser.adql import ADQLQueryTranslator
adql = "SELECT TOP 100 POINT('ICRS', ra, dec) FROM db.tab;"
adt = ADQLQueryTranslator(adql)

and calling

adt.to_postgresql()

which returns a translated string representing a valid PostgreSQL query if the ADQL query had no errors. The PostgreSQL query can then be parsed with the PostgreSQLQueryProcessor in the same way as shown above.

Testing

First in the root directory of the project, install optional dependencies (PyYAML and pytest) by running

python -m pip install .[test]

then run the test suite with

python -m pytest lib/

Metadata

Release files for queryparser-python3 0.8.0.dev0

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

Source distribution (sdist)

Source distribution for queryparser-python3 0.8.0.dev0
File Size Uploaded
queryparser_python3-0.8.0.dev0.tar.gz 267.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for queryparser-python3 0.8.0.dev0
File Interpreter ABI Platform
queryparser_python3-0.8.0.dev0-py3-none-any.whl Python 3 none any Details

Total release size: 539.5 kB

Release files / queryparser_python3-0.8.0.dev0.tar.gz

Download URL queryparser_python3-0.8.0.dev0.tar.gz
Size 267.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ac7f48adf7ec5e96237a3ee171838b8eebc59fbf45d787df94d8fd0028ec7d77
BLAKE2b-256 checksum
How to use checksums
ae0655000e54d672249360f546483b84e401c3a4d39c3bd186caa207c9ba1240
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.0

Release files / queryparser_python3-0.8.0.dev0-py3-none-any.whl

Download URL queryparser_python3-0.8.0.dev0-py3-none-any.whl
Size 272.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
09ea3975e02713cf0f57102c53b923334368e638e1fb270e7d482b168f37930e
BLAKE2b-256 checksum
How to use checksums
7b705fb7726c219b7c515ab40ca37f49392d0c0aee777be8d82b607eaca8e978
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.0

Release history Release notifications | RSS feed

0.8.0

2 release files

This release

0.8.0.dev0 This release

2 release files

0.7.4

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.6

1 release file

0.4.5

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.4

1 release file

0.3

1 release file

0.2.9

1 release file

0.2.8

1 release file

0.2.7

1 release file

0.2.6

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1

1 release file

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