actio_python_utils.database_functions.get_db_args

actio_python_utils.database_functions.get_db_args(service=None, db_args=None, logger=None, cursor_factory=<class 'actio_python_utils.database_functions.LoggingCursor'>)[source]

Returns a dict of arguments to log in with psycopg2. Resolution order for connecting to a database is as follows:

    1. service, referring to a PostgreSQL service name, normally defined in ~/.pg_service.conf

    2. db_args, arbitrary dictionary of arguments

  1. Environment variable $DB_CONNECTION_STRING with format:

    postgres://your_user:your_password@your_host:your_port/your_database
    
  2. Environment variable $PGSERVICE, referring to a PostgreSQL service name

  3. cfg["db"], which should resolve to a dictionary of arguments

Parameters:
  • service (Optional[str], default: None) – The PostgreSQL service to connect to

  • db_args (Optional[Mapping[Hashable, Any]], default: None) – A mapping of database connection arguments

  • logger (Optional[Logger], default: None) – Optional logger to write to

  • cursor_factory (cursor, default: <class 'actio_python_utils.database_functions.LoggingCursor'>) – The class of cursor to use for the connection by default (used for service/$DB_CONNECTION_STRING)

Raises:

ValueError – If service and db_args are specified

Return type:

dict

Returns:

The dict of login arguments