https://github.com/gmr/pgparse
Python wrapper for libpg_query
https://github.com/gmr/pgparse
postgresql python3 sql
Last synced: 8 months ago
JSON representation
Python wrapper for libpg_query
- Host: GitHub
- URL: https://github.com/gmr/pgparse
- Owner: gmr
- License: bsd-3-clause
- Created: 2019-07-09T17:11:07.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2022-08-21T12:55:16.000Z (over 3 years ago)
- Last Synced: 2025-06-16T07:08:06.981Z (10 months ago)
- Topics: postgresql, python3, sql
- Language: Python
- Homepage: https://pgparse.readthedocs.io
- Size: 111 KB
- Stars: 3
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
pgparse
=======
Python wrapper for `libpg_query `_
|Version| |Coverage| |License| |Docs|
Installation
------------
.. code-block:: bash
pip install pgparse
Example Usage
-------------
The following example shows how to create a dump and then read it in, and
iterate through the data of one of the tables.
.. code-block:: python
import pprint
import pgparse
sql = "SELECT * FROM pg_catalog.pg_class WHERE relname = 'foo'"
print('Fingerprint: {}'.format(pgparse.fingerprint(sql)))
print('Normalized: {!r}'.format(pgparse.normalize(sql)))
parsed = pgparse.parse(sql)
pprint.pprint(parsed)
func = """\
CREATE FUNCTION sales_tax(subtotal real) RETURNS real AS $$
BEGIN
RETURN subtotal * 0.06;
END;
$$ LANGUAGE plpgsql;
"""
parsed = pgparse.parse_pgsql(func)
pprint.pprint(parsed)
.. |Version| image:: https://img.shields.io/pypi/v/pgparse.svg?
:target: https://pypi.python.org/pypi/pgparse
:alt: Package Version
.. |Coverage| image:: https://codecov.io/gh/gmr/pgparse/branch/main/graph/badge.svg
:target: https://codecov.io/github/gmr/pgparse?branch=main
:alt: Code Coverage
.. |License| image:: https://img.shields.io/pypi/l/pgparse.svg?
:target: https://github.com/gmr/pgparse/blob/main/LICENSE
:alt: BSD
.. |Docs| image:: https://img.shields.io/readthedocs/pgparse.svg?
:target: https://pgparse.readthedocs.io/
:alt: Documentation Status