queryparser-python3


Namequeryparser-python3 JSON
Version 0.7.4 PyPI version JSON
download
home_pageNone
SummaryPackage for parsing PostgreSQL/MySQL and translating ADQL to PostgreSQL/MySQL.
upload_time2025-08-18 12:54:33
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseApache-2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            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](https://github.com/django-daiquiri/daiquiri)
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](https://github.com/aipescience/queryparser/actions/workflows/pytest.yml/badge.svg)](https://github.com/aipescience/queryparser/actions/workflows/pytest.yml)
[![Coverage Status](https://coveralls.io/repos/aipescience/queryparser/badge.svg?branch=master&service=github)](https://coveralls.io/github/aipescience/queryparser?branch=master)
[![License](http://img.shields.io/badge/license-APACHE-blue.svg?style=flat)](https://github.com/aipescience/queryparser/blob/master/LICENSE)
[![Latest Version](https://img.shields.io/pypi/v/queryparser-python3.svg?style=flat)](https://pypi.org/project/queryparser-python3/)



Installation
------------

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

```bash
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

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

After cloning the project run

```bash
make
```

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

```bash
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](https://github.com/kimakan/pgsphere/tree/aiprdbms16) installed.
Although the `pg_sphere` is not required for the python module, the PostgreSQL
**queries will not run** without this extension installed on 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

```python
from queryparser.mysql import MySQLQueryProcessor
qp = MySQLQueryProcessor()
```

feeding it a MySQL query

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

and running it with

```python
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:

```python
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

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

and calling

```python
adt.to_postgresql()
```

which returns a translated string representing a valid MySQL 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

```bash
python -m pip install .[test]
```

then run the test suite with

```bash
python -m pytest lib/
```


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "queryparser-python3",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "Kirill Makan <kmakan@aip.de>, Simeon Reusch <sreusch@aip.de>",
    "keywords": null,
    "author": null,
    "author_email": "Gal Matijevic <gmatijevic@aip.de>",
    "download_url": "https://files.pythonhosted.org/packages/d5/12/6404799a93780f64be15fc9a49a2d0d58fc6e1238f7f8d6dc9a47cc76162/queryparser_python3-0.7.4.tar.gz",
    "platform": null,
    "description": "queryparser\n===========\n\n**Tool for parsing and processing of (MySQL\\*)/PostgreSQL and translation of\nADQL SELECT-like queries**\n\nDesigned to be used in conjunction with [django-daiquri](https://github.com/django-daiquiri/daiquiri)\nas a query processing backend but it can be easily used as a stand-alone tool\nor integrated into another project.\n\n**\\*NOTE: Since version 0.7.0 MySQL is not supported (maintained) anymore.**\n\n\n[![pytest Workflow Status](https://github.com/aipescience/queryparser/actions/workflows/pytest.yml/badge.svg)](https://github.com/aipescience/queryparser/actions/workflows/pytest.yml)\n[![Coverage Status](https://coveralls.io/repos/aipescience/queryparser/badge.svg?branch=master&service=github)](https://coveralls.io/github/aipescience/queryparser?branch=master)\n[![License](http://img.shields.io/badge/license-APACHE-blue.svg?style=flat)](https://github.com/aipescience/queryparser/blob/master/LICENSE)\n[![Latest Version](https://img.shields.io/pypi/v/queryparser-python3.svg?style=flat)](https://pypi.org/project/queryparser-python3/)\n\n\n\nInstallation\n------------\n\nThe easiest way to install the package is by using the pip tool:\n\n```bash\npython -m pip install queryparser-python3\n```\n\nAlternatively, you can clone the repository and install it from there.\nHowever, this step also requires generating the parser which is a slightly\nmore elaborate process (see below).\n\n\nGenerating the parser from the git repository\n---------------------------------------------\n\nTo generate the parsers you need `python3` , `java` above version\n7, and `antlr4` (`antlr-4.*-complete.jar` has to be installed inside the\n`/usr/local/lib/`, `/usr/local/bin/`  or root directory of the project).\n\nThe current version of `antlr-4.*-complete.jar` can be downloaded via\n\n```bash\nwget http://www.antlr.org/download/antlr-4.13.1-complete.jar\n```\n\nAfter cloning the project run\n\n```bash\nmake\n```\n\nand a `lib` directory will be created. After that, run\n\n```bash\npython -m pip install .\n```\n\nto install the generated parser in your virtual environment.\n\n\nAdditional requirements\n-----------------------\nThe queryparser assumes that the PostgreSQL database has the extension\n[pg_sphere](https://github.com/kimakan/pgsphere/tree/aiprdbms16) installed.\nAlthough the `pg_sphere` is not required for the python module, the PostgreSQL\n**queries will not run** without this extension installed on the database.\n\n\nParsing MySQL and PostgreSQL\n----------------------------\n\n**Since version 0.7, MySQL part of the parser is not maintained anymore.\nThus, the MySQL related functionality cannot be guaranteed!**\n\nParsing and processing of MySQL queries can be done by creating an instance\nof the `MySQLQueryProcessor` class\n\n```python\nfrom queryparser.mysql import MySQLQueryProcessor\nqp = MySQLQueryProcessor()\n```\n\nfeeding it a MySQL query\n\n```python\nsql = \"SELECT a FROM db.tab;\"\nqp.set_query(sql)\n```\n\nand running it with\n\n```python\nqp.process_query()\n```\n\nAfter the processing is completed, the processor object `qp` will include\ntables, columns, functions, and keywords used in the query or will raise a\n`QuerySyntaxError` if there are any syntax errors in the query.\n\nAlternatively, passing the query at initialization automatically processes it.\n\nPostgreSQL parsing is very similar to MySQL, except it requires importing\nthe `PostgreSQLProcessor` class:\n\n```python\nfrom queryparser.postgresql import PostgreSQLQueryProcessor\nqp = PostgreSQLQueryProcessor()\n```\n\nThe rest of the functionality remains the same.\n\n\nTranslating ADQL\n----------------\n\nTranslation of ADQL queries is done similarly by first creating an instance of\nthe `ADQLQueryTranslator` class\n\n```python\nfrom queryparser.adql import ADQLQueryTranslator\nadql = \"SELECT TOP 100 POINT('ICRS', ra, de) FROM db.tab;\"\nadt = ADQLQueryTranslator(adql)\n```\n\nand calling\n\n```python\nadt.to_postgresql()\n```\n\nwhich returns a translated string representing a valid MySQL query if\nthe ADQL query had no errors. The PostgreSQL query can then be parsed with the\n`PostgreSQLQueryProcessor` in the same way as shown above.\n\nTesting\n-------\n\nFirst in the root directory of the project, install optional dependencies \n(`PyYAML` and `pytest`) by running\n\n```bash\npython -m pip install .[test]\n```\n\nthen run the test suite with\n\n```bash\npython -m pytest lib/\n```\n\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Package for parsing PostgreSQL/MySQL and translating ADQL to PostgreSQL/MySQL.",
    "version": "0.7.4",
    "project_urls": {
        "Changelog": "https://github.com/aipescience/queryparser/blob/master/CHANGELOG.md",
        "Issues": "https://github.com/aipescience/queryparser/issues",
        "Repository": "https://github.com/aipescience/queryparser.git"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "0c450a6faf18b0745f5815d23682925c26f44070f762c8cf451746d81355e05f",
                "md5": "7e7d2d21c7511eca4ca8c10cd21ce5ea",
                "sha256": "232f3976d169122c6bc95e59525315f7cb8e9a100678ee7e337d453244f818f2"
            },
            "downloads": -1,
            "filename": "queryparser_python3-0.7.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7e7d2d21c7511eca4ca8c10cd21ce5ea",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 274240,
            "upload_time": "2025-08-18T12:54:31",
            "upload_time_iso_8601": "2025-08-18T12:54:31.531114Z",
            "url": "https://files.pythonhosted.org/packages/0c/45/0a6faf18b0745f5815d23682925c26f44070f762c8cf451746d81355e05f/queryparser_python3-0.7.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "d5126404799a93780f64be15fc9a49a2d0d58fc6e1238f7f8d6dc9a47cc76162",
                "md5": "1ac67876620b578ab6c67ad73000b8e7",
                "sha256": "319f941054a6bf97e59370c70ba88c1407bdbb9d87dcfd1f4fabead93facc341"
            },
            "downloads": -1,
            "filename": "queryparser_python3-0.7.4.tar.gz",
            "has_sig": false,
            "md5_digest": "1ac67876620b578ab6c67ad73000b8e7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 269235,
            "upload_time": "2025-08-18T12:54:33",
            "upload_time_iso_8601": "2025-08-18T12:54:33.476088Z",
            "url": "https://files.pythonhosted.org/packages/d5/12/6404799a93780f64be15fc9a49a2d0d58fc6e1238f7f8d6dc9a47cc76162/queryparser_python3-0.7.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-18 12:54:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "aipescience",
    "github_project": "queryparser",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "queryparser-python3"
}
        
Elapsed time: 4.55326s