I'm trying to connect to a postgres db using SQL Alchemy and the pg8000 driver. I'd like to specify a search path for this connection. With the Psycopg driver, I could do this by doing something like
engine = create_engine(
'postgresql+psycopg2://dbuser@dbhost:5432/dbname',
connect_args={'options': '-csearch_path={}'.format(dbschema)})
However, this does not work for the pg8000 driver. Is there a good way to do this?
You can use
pg8000
pretty much in the same way aspsycopg2
, just need to swap scheme frompostgresql+psycopg2
topostgresql+pg8000
.The full connection string definition is in the SQLAlchemy
pg8000
docs:But while
psycopg2.connect
will pass kwargs to the server (likeoptions
and its content),pg8000.connect
will not, so there is no settingsearch_path
withpg8000
.