Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/razerm/pg_grant

Python library to parse PostgreSQL privileges
https://github.com/razerm/pg_grant

postgresql postgresql-database privileges python

Last synced: 3 months ago
JSON representation

Python library to parse PostgreSQL privileges

Awesome Lists containing this project

README

        

pg_grant
-------------

|PyPI Version| |Documentation| |Coverage| |Python Version| |PostgreSQL Version| |License|

``pg_grant`` is a Python module for parsing, querying, and updating PostgreSQL
privileges.

Installation
~~~~~~~~~~~~

.. code:: bash

$ pip install pg_grant[sqlalchemy]

Without the SQLAlchemy extra, ``pg_grant`` can only parse access privileges.

Example
~~~~~~~

.. code:: pycon

>>> from pg_grant import parse_acl_item
>>> parse_acl_item("bob=arw*/alice")
Privileges(grantee='bob', grantor='alice', privs=['SELECT', 'INSERT'], privswgo=['UPDATE'])

>>> from sqlalchemy import create_engine
>>> from pg_grant.query import get_table_acl
>>> engine = create_engine("postgresql://...")
>>> with engine.connect() as conn:
... get_table_acl(conn, "table2")
...
SchemaRelationInfo(oid=138067, name='table2', owner='alice', acl=['alice=arwdDxt/alice', 'bob=arwdDxt/alice'], schema='public')

>>> from pg_grant import PgObjectType
>>> from pg_grant.sql import revoke
>>> stmt = revoke(["SELECT"], PgObjectType.TABLE, "table2", "bob")
>>> str(stmt)
'REVOKE SELECT ON TABLE table2 FROM bob'
>>> engine.execute(stmt)

Authors
~~~~~~~
- Frazer McLean

Documentation
~~~~~~~~~~~~~

For in-depth information, `visit the
documentation `__!

Development
~~~~~~~~~~~

pg_grant uses `semantic versioning `__

.. |PyPI Version| image:: http://img.shields.io/pypi/v/pg_grant.svg?style=flat-square&label=PyPI
:target: https://pypi.python.org/pypi/pg_grant/
.. |Python Version| image:: https://img.shields.io/badge/Python-3-brightgreen.svg?style=flat-square
:target: https://www.python.org/downloads/
.. |PostgreSQL Version| image:: https://img.shields.io/badge/PostgreSQL-9.5--12-blue.svg?style=flat-square
:target: https://www.postgresql.org/
.. |License| image:: https://img.shields.io/github/license/RazerM/pg_grant.svg?style=flat-square
:target: https://raw.githubusercontent.com/RazerM/pg_grant/master/LICENSE.txt
.. |Coverage| image:: https://img.shields.io/codecov/c/github/RazerM/pg_grant/master.svg?style=flat-square
:target: https://codecov.io/github/RazerM/pg_grant?branch=master
.. |Documentation| image:: https://img.shields.io/badge/docs-latest-brightgreen.svg?style=flat-square
:target: https://pg-grant.readthedocs.org/en/latest/