Connection Pooling

Connection pooling is provided by the pool module, included in the playhouse extensions library. The pool supports:

  • Timeout after which connections will be recycled.
  • Upper bound on the number of open connections.
  1. from playhouse.pool import PooledPostgresqlExtDatabase
  2. db = PooledPostgresqlExtDatabase(
  3. 'my_database',
  4. max_connections=8,
  5. stale_timeout=300,
  6. user='postgres')
  7. class BaseModel(Model):
  8. class Meta:
  9. database = db

The following pooled database classes are available:

For an in-depth discussion of peewee’s connection pool, see the Connection pool section of the playhouse documentation.