pgcom.commuter.Commuter

class Commuter(pool_size: int = 20, pre_ping: bool = False, max_reconnects: int = 3, **kwargs: str)[source]

Communication agent.

When creating a new instance of Commuter, the connection pool is created and the connection is established. The typical usage of Commuter is therefore once per particular database, held globally for the lifetime of a single application process.

Parameters
  • pool_size – The maximum amount of connections the pool will support.

  • pre_ping – If True, the pool will emit a “ping” on the connection to test if the connection is alive. If not, the connection will be reconnected.

  • max_reconnects – The maximum amount of reconnects, defaults to 3.

Methods

copy_from(table_name, data[, format_data, ...])

Places DataFrame to a buffer and apply COPY FROM command.

delete_entry(table_name, **kwargs)

Delete entry from the table.

encode_category(data, category, key, ...[, ...])

Encode categorical column.

encode_composite_category(data, categories, ...)

Encode categories represented by multiple columns.

execute(cmd[, values])

Execute a database operation (query or command).

execute_script(path2script)

Execute query from file.

get_connections_count()

Returns the amount of active connections.

insert(table_name, data[, columns, placeholders])

Write rows from a DataFrame to a database table.

insert_return(cmd[, values, return_id])

Insert a new row to the table and return the serial key of the newly inserted row.

insert_row(table_name[, return_id])

Implements insert command.

is_entry_exist(table_name, **kwargs)

Return True if entry already exists, otherwise return False.

is_table_exist(table_name)

Return True if table exists, otherwise False.

make_where(keys)

Build WHERE clause from list of keys.

resolve_foreign_conflicts(table_name, ...[, ...])

Resolve foreign key conflicts in DataFrame.

resolve_primary_conflicts(table_name, data)

Resolve primary key conflicts in DataFrame.

select(cmd[, values])

Read SQL query into a DataFrame.

select_one(cmd[, values, default])

Select the first element of returned DataFrame.

Properties

connector