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
ustogres-3.0.1.tar.gz
(2.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ustogres-3.0.1.tar.gz.
File metadata
- Download URL: ustogres-3.0.1.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.10.1 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
244045be27fab6db06494ac56a5a118ba850230919576abd67bbb698e15835fe
|
|
| MD5 |
ddb196b9c889aa2372aea26e320a5338
|
|
| BLAKE2b-256 |
43cbcfa69cfbeead03241d2cd8b4d77b246ad75c9269bec4b03c3ddcca960a25
|
File details
Details for the file ustogres-3.0.1-py3-none-any.whl.
File metadata
- Download URL: ustogres-3.0.1-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.10.1 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ce891d587dbe973593cddaed8fd83b067dec210ead6e506afb2fa9c11a50f6a
|
|
| MD5 |
ab021c395f58628722f95af4cfc95d98
|
|
| BLAKE2b-256 |
6e215198b6705284def1a7e931e13398f63b8190aef71fe05ae3220d905a9190
|