sqlalchemy check if database exists

# pip install sqlalchemy-utils

from sqlalchemy_utils.functions import database_exists

if database_exists(app.config["SQLALCHEMY_DATABASE_URI"]):
    # do stuff

Here is what the above code is Doing:
1. Importing the database_exists function from sqlalchemy_utils.
2. Checking if the database exists.
3. If the database exists, do something.

If you want to create the database, you can use the create_database function:

from sqlalchemy_utils.functions import create_database

if not database_exists(app.config[“SQLALCHEMY_DATABASE_URI”]):