Name | queryparser-python3 JSON |
Version |
0.7.0
JSON |
| download |
home_page | None |
Summary | Package for parsing PostgreSQL/MySQL and translating ADQL to PostgreSQL/MySQL. |
upload_time | 2024-05-21 13:36:42 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | Apache-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>",
"keywords": null,
"author": null,
"author_email": "Gal Matijevic <gmatijevic@aip.de>",
"download_url": "https://files.pythonhosted.org/packages/da/d0/4fdd3f0e704b3add299f3f9127788deaf3ec61d3e3e57503af4251e14103/queryparser_python3-0.7.0.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.0",
"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": "",
"digests": {
"blake2b_256": "d518fb759a262e6bf7106445147025c3e518e345c192edc226461858cf5b2c4c",
"md5": "8fe2db1a9656682b0122d1c15e3d1be0",
"sha256": "73483fa8818e9ddf9e07c95147852238452292d38fcd3e11cefa3ad3337fc455"
},
"downloads": -1,
"filename": "queryparser_python3-0.7.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8fe2db1a9656682b0122d1c15e3d1be0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 271030,
"upload_time": "2024-05-21T13:36:38",
"upload_time_iso_8601": "2024-05-21T13:36:38.119001Z",
"url": "https://files.pythonhosted.org/packages/d5/18/fb759a262e6bf7106445147025c3e518e345c192edc226461858cf5b2c4c/queryparser_python3-0.7.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "dad04fdd3f0e704b3add299f3f9127788deaf3ec61d3e3e57503af4251e14103",
"md5": "6cb767a4d9ce348dfab0c578e7153b18",
"sha256": "d1d35f73c034fac92bd526f8f68ce006988a7744e0fc35f7a3525051903c3d2e"
},
"downloads": -1,
"filename": "queryparser_python3-0.7.0.tar.gz",
"has_sig": false,
"md5_digest": "6cb767a4d9ce348dfab0c578e7153b18",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 266233,
"upload_time": "2024-05-21T13:36:42",
"upload_time_iso_8601": "2024-05-21T13:36:42.179158Z",
"url": "https://files.pythonhosted.org/packages/da/d0/4fdd3f0e704b3add299f3f9127788deaf3ec61d3e3e57503af4251e14103/queryparser_python3-0.7.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-21 13:36:42",
"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"
}