You would need to pip install SQLAlchemy
and pip install psycopg2
.
An example of a SQLAlchemy connection string that uses psycopg2:
from sqlalchemy import create_engine
engine = create_engine('postgresql+psycopg2://user:password@hostname/database_name')
You could also connect to your database using the psycopg2 driver exclusively:
import psycopg2
conn_string = "host='localhost' dbname='my_database' user='postgres' password='secret'"
conn = psycopg2.connect(conn_string)
However, using the psycopg2 driver to connect does not take advantage of SQLAlchemy.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…