Connection Pooling

Connection pooling is provided by the pool module, included inthe 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.  
  3. db = PooledPostgresqlExtDatabase(
  4. 'my_database',
  5. max_connections=8,
  6. stale_timeout=300,
  7. user='postgres')
  8.  
  9. class BaseModel(Model):
  10. class Meta:
  11. database = db

The following pooled database classes are available:

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