Database connection API

Use ini file to define database connections. The first block in the example below connect directly to the database, while the second block uses ssh tunnel to connect to database host.

Example of database.ini file
 [mimic]
 host=localhost
 database=mimicii
 user=postgres
 password=*****

 [nsaph2]
 host=nsaph.cluster.uni.edu
 database=nsaph
 user=dbuser
 password=*********
 ssh_user=johndoe

API to establish database connection

Connection details and credentials are specified in database.ini file

This module supports connecting via ssh tunnel. This happens automatically if the given section of database.ini contains ssh_user key.

class Connection(filename=None, section=None, silent: bool = False, app_name_postfix='')[source]
default_filename = 'database.ini'
default_section = 'postgresql'
aws_default_region = 'us-east-1'
aws_default_secret_name = 'nsaph/public/dorieh/'
classmethod read_config(filename, section)[source]
classmethod get_aws_secret(region_name=None, secret_name=None)[source]
static host_name()[source]
classmethod resolve_host(host)[source]
static default_port() int[source]
pid() int[source]
static get_pid(connection) int[source]
connect_to_database(params)[source]
connect(autocommit=None)[source]
connect_via_tunnel()[source]
get_database_types()[source]
close()[source]
test_connection()[source]
class ResultSetDeprecated(*args, **kwargs)[source]

Deprecated since version 0.2: Use psycopg2.extras.RealDictCursor

SIZE = 10000