peewee-async — peewee-async 0.6.1a documentation (original) (raw)

peewee-async

peewee-async is a library providing asynchronous interface powered by asyncio for peewee ORM.

Current state: alpha, yet API seems fine and mostly stable.

In current version (0.5.x) new-high level API is introduced while older low-level API partially marked as deprecated.

The source code is hosted on GitHub.

Quickstart

import asyncio import peewee import peewee_async

Nothing special, just define model and database:

database = peewee_async.PostgresqlDatabase('test')

class TestModel(peewee.Model): text = peewee.CharField()

class Meta:
    database = database

Look, sync code is working!

TestModel.create_table(True) TestModel.create(text="Yo, I can do it sync!") database.close()

Create async models manager:

objects = peewee_async.Manager(database)

No need for sync anymore!

database.set_allow_sync(False)

async def handler(): await objects.create(TestModel, text="Not bad. Watch this, I'm async!") all_objects = await objects.execute(TestModel.select()) for obj in all_objects: print(obj.text)

loop = asyncio.get_event_loop() loop.run_until_complete(handler()) loop.close()

Clean up, can do it sync again:

with objects.allow_sync(): TestModel.drop_table(True)

Expected output:

Yo, I can do it sync!

Not bad. Watch this, I'm async!

Install

Install latest version from PyPI.

For PostgreSQL:

pip install peewee-async aiopg

For MySQL:

pip install peewee-async aiomysql

Install from sources

git clone https://github.com/05bit/peewee-async.git cd peewee-async python setup.py install

Running tests

Prepare environment for tests:

Then run tests:

Report bugs and discuss

You are welcome to add discussion topics or bug reports to tracker on GitHub!