API Star Peewee ORM
- Version: 0.3.6
- Status: Production/Stable
- Author: José Antonio Perdiguero López
Peewee integration for API Star.
Features
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 = [
PeeweeDatabaseComponent(url='sqlite://'),
]
event_hooks = [
PeeweeTransactionHook(),
]
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 PuppyModel.select()]
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 = [
PeeweeDatabaseComponent(url='sqlite://'),
]
event_hooks = [
PeeweeTransactionHook(),
]
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
(<package>.<module>:<variable>)
optional arguments:
-h, --help show this help message and exit
-s SETTINGS, --settings SETTINGS
Module or object with Clinner settings in format
"package.module[:Object]"
-q, --quiet Quiet mode. No standard output other than executed
application
-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
Commands:
{status,upgrade,downgrade,merge,create}
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.
Metadata
Release files for apistar-peewee-orm 0.3.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| apistar-peewee-orm-0.3.6.tar.gz | 19.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| apistar_peewee_orm-0.3.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 78.4 kB
Release files / apistar-peewee-orm-0.3.6.tar.gz
| Download URL | apistar-peewee-orm-0.3.6.tar.gz |
|---|---|
| Size | 19.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
75f3dd18f493be1f568e6832dffae917cdeffa692a766b0db0d91f636b81c54b
|
|
BLAKE2b-256 checksum How to use checksums |
0017fa7111ef5ce0931d930a6b277f8c72c4dc0834f377c0f86a9bcff0ae4726
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.11.5 CPython/3.7.0 Linux/4.18.14-arch1-1-ARCH
|
Release files / apistar_peewee_orm-0.3.6-py3-none-any.whl
| Download URL | apistar_peewee_orm-0.3.6-py3-none-any.whl |
|---|---|
| Size | 59.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b5567b75ecf54ff80cd7a541d87d5364abbab59f3e45b86a2766497450c6d50f
|
|
BLAKE2b-256 checksum How to use checksums |
b4db85d15bb286e73a0b2c462d8cbe4e19cd112b14b4a93092d5a255f07adc16
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.11.5 CPython/3.7.0 Linux/4.18.14-arch1-1-ARCH
|
Security for apistar-peewee-orm 0.3.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.