class hermes.connectors.PostgresConnector(dsn, cursor_factory=<class 'psycopg2.extras.DictCursor'>)

Postgres-talking connection wrapper. A thin wrapper to encapsulate the complexity of creating, re-creating, and disconnecting from a Postgres database.

Creating a PostgresConnector is done like so:

from psycopg2.extras import DictCursor

# Define a Postgres DSN dictionary
dsn = {'database': 'example_db',
       'host': '',
       'port': 5432,
       'user': 'example',
       'password': 'example'}

cursor_factory = DictCursor

# Pass the DSN to the PostgresConnector's constructor
connector = PostgresConnector(dsn, cursor_factory=cursor_factory)
  • dsn – A Postgres-compatible DSN dictionary
  • cursor_factory – A callable cursor subclass

Disconnects from the Postgres instance unless it is already disconnected.


Enquires as to whether this server is a master or a slave.

Returns:A boolean indicating whether the server is master.

Connects to the Postgres host, if a connection does not exist or is closed, using the the DSN provided in the constructor.

Automatically sets connection isolation level to AUTOCOMMIT.

Returns:A connection object

Opens a postgres cursor if it doesn’t exist or is closed. Otherwise returns the current cursor.

Returns:A psycopg2 cursor instance or subclass as defined by the cursor_factory passed to the constructor