pythonsqlpostgresqlflaskflask-sqlalchemy

How to find postgresql uri for SQLALCHEMY config


I am trying to connect my flask app to my prostgreSQL db, and i find this configuration example (below code). I just do not know how to find my postgreSQL URI

app = Flask(__name__)
#how do i know my postgresql URI
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://localhost/pre-registration'
db = SQLAlchemy(app)

Solution

  • From the documentation of SQLAlchemy (http://docs.sqlalchemy.org/en/latest/core/engines.html#database-urls):

    The typical form of a database URL is:

    dialect+driver://username:password@host:port/database

    This means that, if you have a Postgres DB called my_db running on localhost on port 5432, accessed by username user and password pass, your URL will look like:

    postgresql://user:pass@localhost:5432/my_db