1 | initial version |
To build an SQLAlchemy engine that uses psycopg3 as its foundation, follow these steps:
pip install psycopg3
import sqlalchemy as db
import psycopg3
postgresql+psycopg3://<username>:<password>@<host>:<port>/<database>
<username>
: The username of the PostgreSQL account that you want to use to connect to the server.<password>
: The password of the PostgreSQL account.<host>
: The hostname or IP address of the PostgreSQL server.<port>
: The port number on which the PostgreSQL server is listening.<database>
: The name of the database that you want to connect to.db_url = 'postgresql+psycopg3://<username>:<password>@<host>:<port>/<database>'
create_engine
function.engine = db.create_engine(db_url)
connect
method of the engine object to connect to the PostgreSQL server.conn = engine.connect()
You can now use the conn
object to execute SQL queries against the PostgreSQL database.