Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Utilize Peewee as your ORM with Pyramid webapplications. - pyramid_peewee

Project Description

Pyramid_peewee is a module for the Pyramid web application framework which allos developers to use Peewee as their ORM.


1. Pyramid
2. Peewee
3. Database


Typically Pyramid based applications are configured in two locations, at the application level within the application file and at the instance level within an “ini” file, such as production.ini. To configure your applicaiton, first at the instance (eg production.ini) level you must set peewee.urls = “database connection url”

peewee.urls = sqlite:///dbase.db
peewee.urls =

Note we specifically use database urls as defined in the peewee documentation Connecting using a Database URL and that you may specify as many database urls as your application needs within the peewee.urls paramter. At the application level, eg within your applications file

  1. import your database model
  2. include the command config.include(‘pyramid_peewee’) within the config section.

Define your data model: To define your data model fist set your database = peewee.Proxy. Note if your database contains a “.” in the name, such as with sqlite files replace it with an “_” (underscore).

from peewee import *

mydatabase = Proxy()
dbase_db = Proxy()

class People(Model):
    name = TextField()
    class Meta:
        database = mydatabase

class Cars(model):
    name = TextField()
        class Meta:
            database = dbase_db

In this example we’ve defined two tables, each derived from different database Proxies. Peewee allows you to define as many database connections as you need and utilize them seemlessly within an application.

Using your datamodel within a View:

To utilize your datamodel within a view you must first get a datbase connection. This is accomplished by calling the database proxy which is tied to the view request. By doing so database connections are properly closed as the end of the request.

from model import *
def myView(requset):
    joe ='joe').get()
    return dict(

As stated above by calling request.mydatabase two things are accomplished, one a database connection is opened for the request, and two a callback is registered wich will properly close the connection at the end of the request. Trying to use the model without first calling the database method from the request object will result in an DataBaseClosed error. This is a devation from the normal PeeWee behavior which normaly opens a connection as needed.

Supported database urls from the PeeWee documentation:

  1. sqlite:///my_database.db will create a SqliteDatabase instance for the file my_database.db in the current directory.
  2. sqlite:///:memory: will create an in-memory SqliteDatabase instance.
  3. postgresql://postgres:my_password@localhost:5432/my_database will create a PostgresqlDatabase instance. A username and password are provided, as well as the host and port to connect to.
  4. mysql://user:passwd@ip:port/my_db will create a MySQLDatabase instance for the local MySQL database my_db.

Supported schemes:

  1. apsw: APSWDatabase
  2. mysql: MySQLDatabase
  3. mysql+pool: PooledMySQLDatabase
  4. postgres: PostgresqlDatabase
  5. postgres+pool: PooledPostgresqlDatabase
  6. postgresext: PostgresqlExtDatabase
  7. postgresext+pool: PooledPostgresqlExtDatabase
  8. sqlite: SqliteDatabase
  9. sqliteext: SqliteExtDatabase

The most up to date documentation can always be found on their website: Peewee Database URL

Release History

Release History

This version
History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
pyramid_peewee-0.5-py3-none-any.whl (8.2 kB) Copy SHA256 Checksum SHA256 3.4 Wheel Aug 5, 2015
pyramid_peewee-0.5.tar.gz (5.0 kB) Copy SHA256 Checksum SHA256 Source Aug 5, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting