module documentation

Changed in version 1.4: The pg8000 dialect has been updated for version 1.16.6 and higher, and is again part of SQLAlchemy's continuous integration with full feature support.

Unicode

pg8000 will encode / decode string values between it and the server using the PostgreSQL client_encoding parameter; by default this is the value in the postgresql.conf file, which often defaults to SQL_ASCII. Typically, this can be changed to utf-8, as a more useful default:

#client_encoding = sql_ascii # actually, defaults to database
                             # encoding
client_encoding = utf8

The client_encoding can be overridden for a session by executing the SQL:

SET CLIENT_ENCODING TO 'utf8';

SQLAlchemy will execute this SQL on all new connections based on the value passed to _sa.create_engine using the client_encoding parameter:

engine = create_engine(
    "postgresql+pg8000://user:pass@host/dbname", client_encoding='utf8')

SSL Connections

pg8000 accepts a Python SSLContext object which may be specified using the :paramref:`_sa.create_engine.connect_args` dictionary:

import ssl
ssl_context = ssl.create_default_context()
engine = sa.create_engine(
    "postgresql+pg8000://scott:tiger@192.168.0.199/test",
    connect_args={"ssl_context": ssl_context},
)

If the server uses an automatically-generated certificate that is self-signed or does not match the host name (as seen from the client), it may also be necessary to disable hostname checking:

import ssl
ssl_context = ssl.create_default_context()
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
engine = sa.create_engine(
    "postgresql+pg8000://scott:tiger@192.168.0.199/test",
    connect_args={"ssl_context": ssl_context},
)

pg8000 Transaction Isolation Level

The pg8000 dialect offers the same isolation level settings as that of the :ref:`psycopg2 <psycopg2_isolation_level>` dialect:

  • READ COMMITTED
  • READ UNCOMMITTED
  • REPEATABLE READ
  • SERIALIZABLE
  • AUTOCOMMIT
Class ​_PGARRAY Undocumented
Class _​PGBig​Integer Undocumented
Class _​PGBoolean Undocumented
Class _​PGEnum Undocumented
Class _​PGInteger Undocumented
Class _​PGInterval Undocumented
Class ​_PGJSON Undocumented
Class ​_PGJSONB Undocumented
Class _​PGJSONIndex​Type Undocumented
Class _​PGJSONInt​Index​Type Undocumented
Class _​PGJSONPath​Type Undocumented
Class _​PGJSONStr​Index​Type Undocumented
Class _​PGNull​Type Undocumented
Class _​PGNumeric Undocumented
Class _​PGNumeric​No​Bind Undocumented
Class _​PGSmall​Integer Undocumented
Class _​PGTime Undocumented
Class _​PGTime​Stamp Undocumented
Class ​_PGUUID Undocumented
Class ​PGCompiler_pg8000 Undocumented
Class ​PGDialect_pg8000 Undocumented
Class ​PGExecution​Context_pg8000 Undocumented
Class ​PGIdentifier​Preparer_pg8000 Undocumented
Class ​Server​Side​Cursor Undocumented
Variable ​_server​_side​_id Undocumented
_server_side_id =

Undocumented