Installing and Testing

    Peewee comes with a couple C extensions that will be built if Cython is available.

    • Sqlite extensions, which includes Cython implementations of the SQLite date manipulation functions, the REGEXP operator, and full-text search result ranking algorithms.

    The project is hosted at https://github.com/coleifer/peewee and can be installed using git:

    1. cd peewee
    2. python setup.py install

    Note

    On some systems you may need to use sudo python setup.py install to install peewee system-wide.

    You can test your installation by running the test suite.

    1. python runtests.py

    You can test specific features or specific database drivers using the script. To view the available test runner options, use:

    Note

    To run tests against Postgres or MySQL you need to create a database named “peewee_test”. To test the Postgres extension module, you will also want to install the HStore extension in the postgres test database:

    1. -- install the hstore extension on the peewee_test postgres db.
    2. CREATE EXTENSION hstore;

    To use Peewee, you typically won’t need anything outside the standard library, since most Python distributions are compiled with SQLite support. You can test by running import sqlite3 in the Python console. If you wish to use another database, there are many DB-API 2.0-compatible drivers out there, such as pymysql or for MySQL and Postgres respectively.

    • : an optional 3rd-party SQLite binding offering greater performance and comprehensive support for SQLite’s C APIs. Use with APSWDatabase.
    • is an optional dependency for SqliteQueueDatabase (though it works with threading just fine).
    • BerkeleyDB can be compiled with a SQLite frontend, which works with Peewee. Compiling can be tricky so .
    • Lastly, if you use the Flask framework, there are helper extension modules available.

    Peewee includes two SQLite-specific C extensions which provide additional functionality and improved performance for SQLite database users. Peewee will attempt to determine ahead-of-time if SQLite3 is installed, and only build the SQLite extensions if the SQLite shared-library is available on your system.

    If, however, you receive errors like the following when attempting to install Peewee, you can explicitly disable the compilation of the SQLite C extensions by settings the NO_SQLITE environment variable.

    Here is how to install Peewee with the SQLite extensions explicitly disabled:

    1. $ NO_SQLITE=1 python setup.py install