Installation SQLAlchemy

Notes Single

pip install sqlalchemy

In addition to this, the respective driver must be installed to connect to the database:

For MySQL or MariaDB:

pip install pymysql

For PostgreSQL:

pip install psycopg 

Connection

from sqlalchemy import create_engine

In case of MySQL/MariaDB:

# engine = create_engine("mysql+pymysql://user:pass@some_mariadb/dbname?charset=utf8mb4")
engine = create_engine("mysql+pymysql://root@localhost/fastapidb?charset=utf8mb4")

In case of PostgreSQL:

# engine = create_engine("postgresql+psycopg2://scott:tiger@localhost:5432/mydatabase")
engine = create_engine('postgresql://postgres:admin:password@localhost/mydatabasepython')

Thanks for reading :)
I invite you to continue reading other entries and visiting us again soon.

Related Posts: