Pass postgres data to pandas dataframe
Project description
Install
pip install justogres
Usage
0. import
from justogres import clientPsql
1. Create client object
psql = clientPsql(
host = <your host>,
user = <your user>,
password = <your password>,
port=<your port (optional)>,
db_name=<your database name>,
)
2. execute query or insert method
2.1 exec_query()
psql.exec_query(
<your sql query>,
chunksize = <chunksize (optional)>)
if query return something, method return pandas.Dataframe object
2.2 insert() -> return None
psql.insert(
<your pd.DataFrame object>,
table_name=<your table name>, #if doesn't exist, will be created
schema=<your schema name>, #should be created previously
chunksize=<your chunksize to load (default: 1000)>)
Examples:
first we must init client
from justogres import clientPsql
psql = clientPsql(
host = os.environ.get("host_justo_pg"),
user = os.environ.get("username_justo_pg"),
password = os.environ.get("password_justo_pg"),
port=os.environ.get("port_justo_pg"),
db_name='postgres',
)
Then follow this options:
1.if we are gona execute query
q="""DELETE
FROM schema_name.table_name
WHERE column_name='value';"""
psql.exec_query(q)
1.1 (special case) if we are gonna read
q="""SELECT *
FROM schema_name.table_name;"""
df = psql.read(q)
optional: read with pandas library
q="""SELECT *
FROM schema_name.table_name;"""
df = psql.read_with_pandas(q)
2. if we are gonna insert
df = pd.read_csv('example.csv')
psql.insert(
df,
table_name='test_table',
schema='test_schema',
)
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
justogres-3.0.1.tar.gz
(4.8 kB
view hashes)
Built Distribution
Close
Hashes for justogres-3.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6e237fb122d8f2a3da70eea9ffe1bb88bf7b54ea23139e8bc5b9e79ef158d4c |
|
MD5 | c59f1d0c82fcaaf448b8dcb2f8e772ff |
|
BLAKE2b-256 | 84942fb2043543e3e8c640be6e3560365cc0c986a963e95d4487b38513aea748 |