Skip to main content

This library is used to read or write data in Postgres, MongoDB (Only read) or Google Sheets

Project description

Overview

Justogres is a connector to comunicate pandas.DataFrame objects with postgres database

Quick start

for more details review documentation

Install or upgrade package

install:

pip install justogres

upgrade:

pip install justogres --upgrade

Init module

from justogres import clientPsql

psql = clientPsql(
        host = "<your host>",
        user = "<your user>",
        password = "<your password>",
        db_name = "<your database name>",
    )

Insert data into postgres

import pandas as pd
example_df = pd.DataFrame(data=example_data)

psql.insert(
    example_df,
    table_name=<your table name>, #if doesn't exist table, will be created
    schema=<your schema name>, #should be created previously
  
    #optional
    chunksize=<your chunksize to load (default: 1000)>,
    column_types={<name_column_df>:<data_type postgres>})# if not declare column types, will be assigned automatically

Read table of postgres

we have 2 ways to read DB, both return pandas.DataFrame object but its main difference is the type of data that is assigned to the columns of the dataframe

1. use exec_query() -> all columns are defines as object (string datatype in pandas)

query_example_to_read="""SELECT * 
    FROM schema_name.table_name;"""

df = psql.exec_query(
    query_example_to_read,

    #optional
    chunksize=<your chunksize to load (default: 1000)>
    )

2. use read_with_pandas() -> columns are defined with datatype declare for each column into DB

query_example_to_read="""SELECT * 
    FROM schema_name.table_name;"""

df = psql.read_with_pandas(
    query_example_to_read,

    #optional
    **kwargs=<all attributes we can use with pandas.read_sql()>
    )

for more info of pandas.read_sql()

Execute sql queries

this method doesn't return anything

query_example="""DELETE 
    FROM schema_name.table_name 
    WHERE column_name='value';"""

psql.exec_query(
    query_example,
    #optional
    chunksize=<your chunksize to load (default: 1000)>
    )

SpreadSheets Module

Write DataFrame in Worksheet

from justogres import SpreadSheets

spread_sheet_client = SpreadSheets("credentials.json")
spreadsheet_id = '1SVZDYBw17S1XeRNBW08YA7i29mOfFlGmmF6EWKH84bk'
worksheet_name = 'Result'

spread_sheet_client.append_dataframe(data_frame ,spreadsheet_id, worksheet_name)

Read DataFrame in Worksheet

from justogres import SpreadSheets

spread_sheet_client = SpreadSheets("credentials.json")
spreadsheet_id = '1SVZDYBw17S1XeRNBW08YA7i29mOfFlGmmF6EWKH84bk'
worksheet_name = 'Result'

spread_sheet_client.worksheet_to_dataframe(spreadsheet_id, worksheet_name)

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

justogres-3.0.11.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

justogres-3.0.11-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file justogres-3.0.11.tar.gz.

File metadata

  • Download URL: justogres-3.0.11.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.6

File hashes

Hashes for justogres-3.0.11.tar.gz
Algorithm Hash digest
SHA256 3a2e8dc821346939968b002eaf3f02467201f6300c0472313bfcd50e858d9905
MD5 0e50e674738aa09bfc5b0f53d6d24106
BLAKE2b-256 edf5cf6f7589a13d357a4c6b03545f8257184e4d8610799127e9016109cb2e14

See more details on using hashes here.

File details

Details for the file justogres-3.0.11-py3-none-any.whl.

File metadata

  • Download URL: justogres-3.0.11-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.6

File hashes

Hashes for justogres-3.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 790cc0874dd171221e181da0a1b67a81b5656f0c24e25462cbae4d1c6816df9c
MD5 d5712e4dda7489542c45d319d2e632fa
BLAKE2b-256 073435245d705707711bbfd9c845a942a9e9d0982f02ffda62788976c49b377a

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