Skip to main content

Peewee integration for API Star.

Project description

API Star Peewee ORM

Build Status codecov PyPI version

  • Version: 0.3.6
  • Status: Production/Stable
  • Author: José Antonio Perdiguero López

Peewee integration for API Star.


This library provides:

  • Event hooks to handle connections and commit/rollback behavior based on exceptions in your views.
  • Migrations support with a command-line interface to interact with them.

Quick start

Install API Star Peewee ORM:

pip install apistar-peewee-orm

Create an API Star application adding components and event hooks:

from apistar import App
from apistar_peewee_orm import PeeweeDatabaseComponent, PeeweeTransactionHook

routes = []

components = [

event_hooks = [

app = App(routes=routes, components=components, event_hooks=event_hooks)

Your models now should inherit from a base model defined in this library:

import peewee
from apistar_peewee_orm import Model

class PuppyModel(Model):
    name = peewee.CharField()

Full Example

import typing

import peewee
from apistar import App, http, Route, types, validators
from apistar_peewee_orm import Model, PeeweeDatabaseComponent, PeeweeTransactionHook

class PuppyModel(Model):
    name = peewee.CharField()

class PuppyType(types.Type):
    id = validators.Integer(allow_null=True, default=None)
    name = validators.String()

def list_puppies() -> typing.List[PuppyType]:
    return [PuppyType(puppy) for puppy in]

def create_puppy(puppy: PuppyType, raise_exception: http.QueryParam) -> http.JSONResponse:
    if raise_exception:
        raise Exception

    model = PuppyModel.create(**puppy)
    return http.JSONResponse(PuppyType(model), status_code=201)

routes = [
    Route('/puppy/', 'POST', create_puppy),
    Route('/puppy/', 'GET', list_puppies),

components = [

event_hooks = [

app = App(routes=routes, components=components, event_hooks=event_hooks)

CLI Application

An application will be installed along with this library to provide full support for migrations and some other features of Peewee and API Star.

$ apistar-peewee-orm --help

usage: apistar-peewee-orm [-h] [-s SETTINGS] [-q | -v] [--dry-run]
                          {status,upgrade,downgrade,merge,create} ... [app]

positional arguments:
  app                   API Star application path

optional arguments:
  -h, --help            show this help message and exit
  -s SETTINGS, --settings SETTINGS
                        Module or object with Clinner settings in format
  -q, --quiet           Quiet mode. No standard output other than executed
  -v, --verbose         Verbose level (This option is additive)
  --dry-run             Dry run. Skip commands execution, useful to check
                        which commands will be executed and execution order

    status              Database migrations and models status.
    upgrade             Run database migrations sequentially.
    downgrade           Rollback database migrations sequentially.
    merge               Merge all migrations into a single one.
    create              Create a new migration. If a module is provided then
                        the migration will be automatically generated,
                        otherwise the migration will be empty.

Project details

Download files

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

Files for apistar-peewee-orm, version 0.3.6
Filename, size File type Python version Upload date Hashes
Filename, size apistar_peewee_orm-0.3.6-py3-none-any.whl (59.1 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size apistar-peewee-orm-0.3.6.tar.gz (19.3 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page