Instantiate a database connection (for the use with SQLAlchemy).

    The keyword argument `filepath` specifies the location of the config file
    that contains database connection information. If not given, the default
    of `~/.egoio/config.ini` applies.

    Parameters
    ----------
    filepath : str
        Absolute path of config file including the filename itself
    
    Returns
    -------
    conn : sqlalchemy.engine
        SQLalchemy engine object containing the connection details

def connection(filepath=None, section='oep'):
    """
    Instantiate a database connection (for the use with SQLAlchemy).

    The keyword argument `filepath` specifies the location of the config file
    that contains database connection information. If not given, the default
    of `~/.egoio/config.ini` applies.

    Parameters
    ----------
    filepath : str
        Absolute path of config file including the filename itself
    
    Returns
    -------
    conn : sqlalchemy.engine
        SQLalchemy engine object containing the connection details
    """

    # define default filepath if not provided
    if filepath is None:
        filepath = os.path.join(os.path.expanduser("~"), '.egoio', 'config.ini')

    # does the file exist?
    if not os.path.isfile(filepath):
        print('DB config file {file} not found. '
          'This might be the first run of the tool. '
          .format(file=filepath))
        cfg = create_oedb_config_file(filepath, section=section)
    else:
        cfg = readcfg(filepath, section)
    
    try:
        pw = cfg.get(section, "password")
    except:
        pw = keyring.get_password(section,
                                  cfg.get(section, "username"))
        if pw is None:
            pw = getpass.getpass(prompt='No password found for database "{db}". '
                                        'Enter your password to '
                                        'store it in keyring: '
                                 .format(db=cfg.get(section, 'database')))
            keyring.set_password(section, cfg.get(section, "username"), pw)
        
    # establish connection and return it
    conn = create_engine(
        "postgresql+{dialect}://{user}:{password}@{host}:{port}/{db}".format(
            dialect=cfg.get(section, 'dialect', fallback='psycopg2'),
            user=cfg.get(section, 'username'),
            password=pw,
            host=cfg.get(section, 'host'),
            port=cfg.get(section, 'port'),
            db=cfg.get(section, 'database')))

    return conn