Wrapper around psycopg2 to simplify the process of connecting to a PostgreSQL database and executing queries.
Project description
Simple PostgreSQL Interaction in 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
Dependent Libraries
- Python 3.6+
- PostgreSQL
- 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,
}
with DBConnect(conn_params, return_type=pd.DataFrame) as cursor:
results = cursor.read(**_query_params)
print(results)
Output
category sum: price
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
Release history Release notifications | RSS feed
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.2.tar.gz
(31.9 kB
view hashes)
Built Distribution
Close
Hashes for simplepgsql-0.1.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5dc386639858c91a5dcd5885ef6372070f25c06b4f07bfffc8262ca0aa007e2d |
|
MD5 | ed7e29ff182e8303931cfb8eae379500 |
|
BLAKE2b-256 | 50b1b0b1920a775fc6d3640d26f541f63cd332503b17db5f378f9a79af21cec3 |