Initializing a Database

The Database initialization method expects the name of the databaseas the first parameter. Subsequent keyword arguments are passed to theunderlying database driver when establishing the connection, allowing you topass vendor-specific parameters easily.

For instance, with Postgresql it is common to need to specify the host,user and password when creating your connection. These are not standardPeewee Database parameters, so they will be passed directly back topsycopg2 when creating connections:

  1. db = PostgresqlDatabase(
  2. 'database_name', # Required by Peewee.
  3. user='postgres', # Will be passed directly to psycopg2.
  4. password='secret', # Ditto.
  5. host='db.mysite.com') # Ditto.

As another example, the pymysql driver accepts a charset parameterwhich is not a standard Peewee Database parameter. To set thisvalue, simply pass in charset alongside your other values:

  1. db = MySQLDatabase('database_name', user='www-data', charset='utf8mb4')

Consult your database driver’s documentation for the available parameters: