It is convenient to create an engine by using create_engine()
together with execution_options()
, because it allows to create an engine with readonly access mode (meaning that readonly is applied to all connections of that engine):
from sqlalchemy import create_engine
engine = (create_engine("postgresql://scott:tiger@localhost:5432/mydatabase")
.execution_options(postgresql_readonly=True))
Also possible is the following (found it in the docs):
from sqlalchemy import create_engine
engine = create_engine("postgresql://scott:tiger@localhost:5432/mydatabase",
execution_options={"postgresql_readonly": True})