Skip to main content

Database connection (Postgres, Redshift)

Project description

Python Package

db_conn

To use this package is necessary create file on your home ~

    "~/access_information.json"
        {
            "database_name": {
                "host": "database-db.host.net",
                "user": "user",
                "password": "1234",
                "database": "database_name",
                "port": 5432
            },
        }

⚠️ Warning ❗️

  • Remember, if you put your access_information inside of your project, add this file into .gitignore even if it is a private project, security first 😉

After that to use in code, you just need to:

# if you do not use path var, it will assume default path as ~/access_information.json, if you want to use another path you can pass this new path

# You should pass the 'database_name' that you put on your access_information

# With path:
path = os.path.expanduser("~/access_information.json")
database_access = get_database_access(path)
db_handler = DatabaseHandler(database_access["database_name"])

###########################################################################

# You should pass the 'database_name' that you put on your access_information

# Without path
database_access = get_database_access()
db_handler = DatabaseHandler(database_access["database_name"])

To use this connection properly

query = """
    select 
      *
    from table;
"""
df = pd.DataFrame(db_handler.fetch(query))

After use, you should close connection

db_handler.close()

To create table with time series you can use code below, passing start_date, end_date, timezone and frequency

df_script_dim_table = db_handler.create_dim_date('2020-01-01', '2020-05-06', tz='utc', freq='D')

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

db_conn-1.0.5.tar.gz (4.5 kB view hashes)

Uploaded Source

Built Distribution

db_conn-1.0.5-py3-none-any.whl (5.8 kB view hashes)

Uploaded Python 3

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