Skip to content

Python implementation of postgres meta commands (backslash commands)

License

Notifications You must be signed in to change notification settings

dbcli/pgspecial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

85962ba · Nov 26, 2024
Oct 28, 2023
Nov 26, 2024
Mar 2, 2021
Nov 26, 2024
Jan 18, 2021
Jan 6, 2024
Jan 6, 2024
May 13, 2021
Nov 23, 2015
Apr 3, 2023
Mar 21, 2022
Nov 26, 2024
Jan 6, 2024
Apr 3, 2023
Oct 28, 2023
Nov 26, 2024
Jan 6, 2024
Dec 29, 2022
Dec 29, 2022

Repository files navigation

Meta-commands for Postgres

Build Status Latest Version

This package provides an API to execute meta-commands (AKA "special", or "backslash commands") on PostgreSQL.

Quick Start

This is a python package. It can be installed with:

$ pip install pgspecial

Usage

Once this library is included into your project, you will most likely use the following imports:

from pgspecial.main import PGSpecial
from pgspecial.namedqueries import NamedQueries

Then you will create and use an instance of PGSpecial:

pgspecial = PGSpecial()
for result in pgspecial.execute(cur, sql):
    # Do something

If you want to import named queries from an existing config file, it is convenient to initialize and keep around the class variable in NamedQueries:

from configobj import ConfigObj

NamedQueries.instance = NamedQueries.from_config(
    ConfigObj('~/.config_file_name'))

Contributions:

If you're interested in contributing to this project, first of all I would like to extend my heartfelt gratitude. I've written a small doc to describe how to get this running in a development setup.

https://github.com/dbcli/pgspecial/blob/master/DEVELOP.rst

Please feel free to file an issue if you need help.

Projects using it:

This library is used by the following projects:

pgcli: A REPL for Postgres.

ipython-sql: %%sql magic for IPython

OmniDB: An web tool for database management

If you find this module useful and include it in your project, I'll be happy to know about it and list it here.