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.
from playhouse.pool import PooledPostgresqlExtDatabase
db = PooledPostgresqlExtDatabase(
'my_database',
max_connections=8,
stale_timeout=300,
user='postgres')
class BaseModel(Model):
class Meta:
database = db
The following pooled database classes are available:
PooledPostgresqlDatabase
PooledPostgresqlExtDatabase
PooledMySQLDatabase
PooledSqliteDatabase
PooledSqliteExtDatabase
For an in-depth discussion of peewee’s connection pool, see the Connection pool section of the playhouse documentation.