{"id":13440824,"url":"https://github.com/dbcli/pgcli","last_synced_at":"2025-05-12T16:24:14.343Z","repository":{"id":21804031,"uuid":"25126616","full_name":"dbcli/pgcli","owner":"dbcli","description":"Postgres CLI with autocompletion and syntax highlighting","archived":false,"fork":false,"pushed_at":"2025-05-04T17:38:19.000Z","size":10796,"stargazers_count":12428,"open_issues_count":38,"forks_count":558,"subscribers_count":141,"default_branch":"main","last_synced_at":"2025-05-12T16:24:11.825Z","etag":null,"topics":["database","postgres","postgresql","psql","python"],"latest_commit_sha":null,"homepage":"http://pgcli.com","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dbcli.png","metadata":{"files":{"readme":"README.rst","changelog":"changelog.rst","contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2014-10-12T17:32:33.000Z","updated_at":"2025-05-11T14:46:56.000Z","dependencies_parsed_at":"2023-10-11T06:47:31.457Z","dependency_job_id":"b9360605-eb38-4619-bb08-1ee2a059e863","html_url":"https://github.com/dbcli/pgcli","commit_stats":{"total_commits":1772,"total_committers":185,"mean_commits":9.578378378378378,"dds":0.7900677200902935,"last_synced_commit":"0fa81ef0e5998654c19860ef7a132cebd64dfe90"},"previous_names":[],"tags_count":92,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbcli%2Fpgcli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbcli%2Fpgcli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbcli%2Fpgcli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbcli%2Fpgcli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dbcli","download_url":"https://codeload.github.com/dbcli/pgcli/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253774701,"owners_count":21962218,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","postgres","postgresql","psql","python"],"created_at":"2024-07-31T03:01:26.702Z","updated_at":"2025-05-12T16:24:14.301Z","avatar_url":"https://github.com/dbcli.png","language":"Python","readme":"We stand with Ukraine\n---------------------\n\nUkrainian people are fighting for their country. A lot of civilians, women and children, are suffering. Hundreds were killed and injured, and thousands were displaced.\n\nThis is an image from my home town, Kharkiv. This place is right in the old city center.\n\n.. image:: screenshots/kharkiv-destroyed.jpg\n\nPicture by @fomenko_ph (Telegram).\n\nPlease consider donating or volunteering.\n\n* https://bank.gov.ua/en/\n* https://savelife.in.ua/en/donate/\n* https://www.comebackalive.in.ua/donate\n* https://www.globalgiving.org/projects/ukraine-crisis-relief-fund/\n* https://www.savethechildren.org/us/where-we-work/ukraine\n* https://www.facebook.com/donate/1137971146948461/\n* https://donate.wck.org/give/393234#!/donation/checkout\n* https://atlantaforukraine.com/\n\n\nA REPL for Postgres\n-------------------\n\n|Build Status| |CodeCov| |PyPI| |netlify|\n\nThis is a postgres client that does auto-completion and syntax highlighting.\n\nHome Page: http://pgcli.com\n\nMySQL Equivalent: http://mycli.net\n\n.. image:: screenshots/pgcli.gif\n.. image:: screenshots/image01.png\n\nQuick Start\n-----------\n\nIf you already know how to install python packages, then you can simply do:\n\n::\n\n    $ pip install -U pgcli\n\n    or\n\n    $ sudo apt-get install pgcli # Only on Debian based Linux (e.g. Ubuntu, Mint, etc)\n    $ brew install pgcli  # Only on macOS\n\nIf you don't know how to install python packages, please check the\n`detailed instructions`_.\n\n.. _`detailed instructions`: https://github.com/dbcli/pgcli#detailed-installation-instructions\n\nUsage\n-----\n\n::\n\n    $ pgcli [database_name]\n\n    or\n\n    $ pgcli postgresql://[user[:password]@][netloc][:port][/dbname][?extra=value[\u0026other=other-value]]\n\nExamples:\n\n::\n\n    $ pgcli local_database\n\n    $ pgcli postgres://amjith:pa$$w0rd@example.com:5432/app_db?sslmode=verify-ca\u0026sslrootcert=/myrootcert\n\nFor more details:\n\n::\n\n    $ pgcli --help\n\n    Usage: pgcli [OPTIONS] [DBNAME] [USERNAME]\n\n    Options:\n      -h, --host TEXT            Host address of the postgres database.\n      -p, --port INTEGER         Port number at which the postgres instance is\n                                 listening.\n      -U, --username TEXT        Username to connect to the postgres database.\n      -u, --user TEXT            Username to connect to the postgres database.\n      -W, --password             Force password prompt.\n      -w, --no-password          Never prompt for password.\n      --single-connection        Do not use a separate connection for completions.\n      -v, --version              Version of pgcli.\n      -d, --dbname TEXT          database name to connect to.\n      --pgclirc FILE             Location of pgclirc file.\n      -D, --dsn TEXT             Use DSN configured into the [alias_dsn] section\n                                 of pgclirc file.\n      --list-dsn                 list of DSN configured into the [alias_dsn]\n                                 section of pgclirc file.\n      --row-limit INTEGER        Set threshold for row limit prompt. Use 0 to\n                                 disable prompt.\n      --less-chatty              Skip intro on startup and goodbye on exit.\n      --prompt TEXT              Prompt format (Default: \"\\u@\\h:\\d\u003e \").\n      --prompt-dsn TEXT          Prompt format for connections using DSN aliases\n                                 (Default: \"\\u@\\h:\\d\u003e \").\n      -l, --list                 list available databases, then exit.\n      --auto-vertical-output     Automatically switch to vertical output mode if\n                                 the result is wider than the terminal width.\n      --warn [all|moderate|off]  Warn before running a destructive query.\n      --help                     Show this message and exit.\n\n``pgcli`` also supports many of the same `environment variables`_ as ``psql`` for login options (e.g. ``PGHOST``, ``PGPORT``, ``PGUSER``, ``PGPASSWORD``, ``PGDATABASE``).\n\nThe SSL-related environment variables are also supported, so if you need to connect a postgres database via ssl connection, you can set set environment like this:\n\n::\n\n    export PGSSLMODE=\"verify-full\"\n    export PGSSLCERT=\"/your-path-to-certs/client.crt\"\n    export PGSSLKEY=\"/your-path-to-keys/client.key\"\n    export PGSSLROOTCERT=\"/your-path-to-ca/ca.crt\"\n    pgcli -h localhost -p 5432 -U username postgres\n\n.. _environment variables: https://www.postgresql.org/docs/current/libpq-envars.html\n\nFeatures\n--------\n\nThe `pgcli` is written using prompt_toolkit_.\n\n* Auto-completes as you type for SQL keywords as well as tables and\n  columns in the database.\n* Syntax highlighting using Pygments.\n* Smart-completion (enabled by default) will suggest context-sensitive\n  completion.\n\n    - ``SELECT * FROM \u003ctab\u003e`` will only show table names.\n    - ``SELECT * FROM users WHERE \u003ctab\u003e`` will only show column names.\n\n* Primitive support for ``psql`` back-slash commands.\n* Pretty prints tabular data.\n\n.. _prompt_toolkit: https://github.com/jonathanslenders/python-prompt-toolkit\n.. _tabulate: https://pypi.python.org/pypi/tabulate\n\nConfig\n------\nA config file is automatically created at ``~/.config/pgcli/config`` at first launch.\nSee the file itself for a description of all available options.\n\nContributions:\n--------------\n\nIf you're interested in contributing to this project, first of all I would like\nto extend my heartfelt gratitude. I've written a small doc to describe how to\nget this running in a development setup.\n\nhttps://github.com/dbcli/pgcli/blob/main/CONTRIBUTING.rst\n\nPlease feel free to reach out to us if you need help.\n\n* Amjith, pgcli author: amjith.r@gmail.com, Twitter: `@amjithr \u003chttp://twitter.com/amjithr\u003e`_\n* Irina, pgcli maintainer: i.chernyavska@gmail.com, Twitter: `@irinatruong \u003chttp://twitter.com/irinatruong\u003e`_\n\nDetailed Installation Instructions:\n-----------------------------------\n\nmacOS:\n======\n\nThe easiest way to install pgcli is using Homebrew.\n\n::\n\n    $ brew install pgcli\n\nDone!\n\nAlternatively, you can install ``pgcli`` as a python package using a package\nmanager called called ``pip``. You will need postgres installed on your system\nfor this to work.\n\nIn depth getting started guide for ``pip`` - https://pip.pypa.io/en/latest/installation/\n\n::\n\n    $ which pip\n\nIf it is installed then you can do:\n\n::\n\n    $ pip install pgcli\n\nIf that fails due to permission issues, you might need to run the command with\nsudo permissions.\n\n::\n\n    $ sudo pip install pgcli\n\nIf pip is not installed check if easy_install is available on the system.\n\n::\n\n    $ which easy_install\n\n    $ sudo easy_install pgcli\n\nLinux:\n======\n\nMany distributions have ``pgcli`` packages.\nRefer to https://repology.org/project/pgcli/versions or your distribution to check the available versions.\n\nAlternatively, you can use tools such as `pipx`_ or `uvx`_ to install the latest published package to an isolated virtual environment.\n\n.. _pipx: https://pipx.pypa.io/\n.. _uvx: https://docs.astral.sh/uv/guides/tools/\n\nRun:\n\n::\n\n    $ pipx install pgcli\n\nto install ``pgcli`` with ``pipx``, or run:\n\n::\n\n    $ uvx pgcli\n\nto run ``pgcli`` by installing on the fly with ``uvx``.\n\nDocker\n======\n\nPgcli can be run from within Docker. This can be useful to try pgcli without\ninstalling it, or any dependencies, system-wide.\n\nTo build the image:\n\n::\n\n    $ docker build -t pgcli .\n\nTo create a container from the image:\n\n::\n\n    $ docker run --rm -ti pgcli pgcli \u003cARGS\u003e\n\nTo access postgresql databases listening on localhost, make sure to run the\ndocker in \"host net mode\". E.g. to access a database called \"foo\" on the\npostgresql server running on localhost:5432 (the standard port):\n\n::\n\n    $ docker run --rm -ti --net host pgcli pgcli -h localhost foo\n\nTo connect to a locally running instance over a unix socket, bind the socket to\nthe docker container:\n\n::\n\n    $ docker run --rm -ti -v /var/run/postgres:/var/run/postgres pgcli pgcli foo\n\n\nIPython\n=======\n\nPgcli can be run from within `IPython \u003chttps://ipython.org\u003e`_ console. When working on a query,\nit may be useful to drop into a pgcli session without leaving the IPython console, iterate on a\nquery, then quit pgcli to find the query results in your IPython workspace.\n\nAssuming you have IPython installed:\n\n::\n\n    $ pip install ipython-sql\n\nAfter that, run ipython and load the ``pgcli.magic`` extension:\n\n::\n\n    $ ipython\n\n    In [1]: %load_ext pgcli.magic\n\n\nConnect to a database and construct a query:\n\n::\n\n    In [2]: %pgcli postgres://someone@localhost:5432/world\n    Connected: someone@world\n    someone@localhost:world\u003e select * from city c where countrycode = 'USA' and population \u003e 1000000;\n    +------+--------------+---------------+--------------+--------------+\n    | id   | name         | countrycode   | district     | population   |\n    |------+--------------+---------------+--------------+--------------|\n    | 3793 | New York     | USA           | New York     | 8008278      |\n    | 3794 | Los Angeles  | USA           | California   | 3694820      |\n    | 3795 | Chicago      | USA           | Illinois     | 2896016      |\n    | 3796 | Houston      | USA           | Texas        | 1953631      |\n    | 3797 | Philadelphia | USA           | Pennsylvania | 1517550      |\n    | 3798 | Phoenix      | USA           | Arizona      | 1321045      |\n    | 3799 | San Diego    | USA           | California   | 1223400      |\n    | 3800 | Dallas       | USA           | Texas        | 1188580      |\n    | 3801 | San Antonio  | USA           | Texas        | 1144646      |\n    +------+--------------+---------------+--------------+--------------+\n    SELECT 9\n    Time: 0.003s\n\n\nExit out of pgcli session with ``Ctrl + D`` and find the query results:\n\n::\n\n    someone@localhost:world\u003e\n    Goodbye!\n    9 rows affected.\n    Out[2]:\n    [(3793, u'New York', u'USA', u'New York', 8008278),\n     (3794, u'Los Angeles', u'USA', u'California', 3694820),\n     (3795, u'Chicago', u'USA', u'Illinois', 2896016),\n     (3796, u'Houston', u'USA', u'Texas', 1953631),\n     (3797, u'Philadelphia', u'USA', u'Pennsylvania', 1517550),\n     (3798, u'Phoenix', u'USA', u'Arizona', 1321045),\n     (3799, u'San Diego', u'USA', u'California', 1223400),\n     (3800, u'Dallas', u'USA', u'Texas', 1188580),\n     (3801, u'San Antonio', u'USA', u'Texas', 1144646)]\n\nThe results are available in special local variable ``_``, and can be assigned to a variable of your\nchoice:\n\n::\n\n    In [3]: my_result = _\n\nPgcli dropped support for:\n\n* Python\u003c3.8 as of 4.0.0.\n* Python\u003c3.9 as of 4.2.0.\n\nThanks:\n-------\n\nA special thanks to `Jonathan Slenders \u003chttps://twitter.com/jonathan_s\u003e`_ for\ncreating `Python Prompt Toolkit \u003chttp://github.com/jonathanslenders/python-prompt-toolkit\u003e`_,\nwhich is quite literally the backbone library, that made this app possible.\nJonathan has also provided valuable feedback and support during the development\nof this app.\n\n`Click \u003chttp://click.pocoo.org/\u003e`_ is used for command line option parsing\nand printing error messages.\n\nThanks to `psycopg \u003chttps://www.psycopg.org/\u003e`_ for providing a rock solid\ninterface to Postgres database.\n\nThanks to all the beta testers and contributors for your time and patience. :)\n\n\n.. |Build Status| image:: https://github.com/dbcli/pgcli/actions/workflows/ci.yml/badge.svg?branch=main\n    :target: https://github.com/dbcli/pgcli/actions/workflows/ci.yml\n\n.. |CodeCov| image:: https://codecov.io/gh/dbcli/pgcli/branch/main/graph/badge.svg\n   :target: https://codecov.io/gh/dbcli/pgcli\n   :alt: Code coverage report\n\n.. |Landscape| image:: https://landscape.io/github/dbcli/pgcli/main/landscape.svg?style=flat\n   :target: https://landscape.io/github/dbcli/pgcli/main\n   :alt: Code Health\n\n.. |PyPI| image:: https://img.shields.io/pypi/v/pgcli.svg\n    :target: https://pypi.python.org/pypi/pgcli/\n    :alt: Latest Version\n\n.. |netlify| image:: https://api.netlify.com/api/v1/badges/3a0a14dd-776d-445d-804c-3dd74fe31c4e/deploy-status\n     :target: https://app.netlify.com/sites/pgcli/deploys\n     :alt: Netlify\n","funding_links":[],"categories":["HarmonyOS","Command-line Tools","Development","Python","资源列表","\u003ca id=\"tag-dev\" href=\"#tag-dev\"\u003eDev\u003c/a\u003e","Applications","命令行工具","其他__大数据","CLI Tools","\u003ca name=\"tools\"\u003e\u003c/a\u003eTools","应用","python","语言资源库","database","Command-line Tools [🔝](#readme)","\u003ca name=\"data-management-tabular\"\u003e\u003c/a\u003eData management - Tabular data","Awesome Python","Compiled list","Other","CLI"],"sub_categories":["Windows Manager","Database","命令行工具","\u003ca id=\"tag-dev.storage\" href=\"#tag-dev.storage\"\u003eStorage\u003c/a\u003e","Development","\u003ca id=\"tag-dev.ops\" href=\"#tag-dev.ops\"\u003eOps\u003c/a\u003e","网络服务_其他","开发","python","Command-line Tools","plv8:","dbcli"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdbcli%2Fpgcli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdbcli%2Fpgcli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdbcli%2Fpgcli/lists"}