Skip to main content

Wrapper around psycopg2 to simplify the process of connecting to a PostgreSQL database and executing queries.

Project description

Simple PostgreSQL Wrapper for Python

This project contains a Python script (simplepgsql.py) that provides a simple interface for interacting with a PostgreSQL database using psycopg2 library.

Getting Started

Install via PIP pip install simplepgsql

Dependent Libraries

  • Python 3.6+
  • psycopg2 Python library
  • Pandas

Usage

from simplepgsql Import DBConnect

conn_params = {
        "host": config['DB']['DB_HOST'],
        "database": config['DB']['DB_NAME'],
        "user": config['DB']['DB_USER'].strip(),
        "password": config['DB']['DB_PASSWORD'].strip(),
        "port": config['DB']['DB_PORT'],
    }

_query_params = {
        "schema": "public",
        "table_name": "film_list",
        "columns": ["category", "price"],
        "aggregate": {
            "price": "SUM"
        },
        "conditions": {
            "length": (60, ">")
        },
        "order_by": ("price", "DESC"),
        "group_by": ["category", "price"],
        "limit": 10,
    }
  results = pgsql.read(**_query_params)
  print(results)

Output

      category  price.sum
0          New     109.78
1       Travel     109.78
2       Family      74.85
3        Games     129.74
4  Documentary      69.86
5    Animation      74.85
6       Sports     119.76
7       Comedy      94.81
8       Horror      89.82
9      Foreign      99.80

License

This project is licensed under the GNU GPL v3 License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simplepgsql-0.1.11.tar.gz (42.4 kB view details)

Uploaded Source

Built Distribution

simplepgsql-0.1.11-py2.py3-none-any.whl (45.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file simplepgsql-0.1.11.tar.gz.

File metadata

  • Download URL: simplepgsql-0.1.11.tar.gz
  • Upload date:
  • Size: 42.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for simplepgsql-0.1.11.tar.gz
Algorithm Hash digest
SHA256 e4c051552ea1d129e665a43593f838ea5a991e9530c852b6b1196d93454636e9
MD5 a81dfcf40dd42ecd182106cd730f919b
BLAKE2b-256 cca1bc06cda9a8f3a38c760082a9644b05cbefd3707d12e251f5a9f351efad9a

See more details on using hashes here.

File details

Details for the file simplepgsql-0.1.11-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for simplepgsql-0.1.11-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3e503a8d1b351ad44ccfb985ef5b51bd16302459f65ae2e752cd091b6b4aa8e7
MD5 446a29bd25f6eb651a85752f3adba14f
BLAKE2b-256 1005983d71397af4151ca4a8276fcce7159ac61011fa55dc1417f1451a1b0088

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page