Skip to main content

Async Peewee

Project description

Build Status

AioPeewee

Asyncio interface for peewee modeled after torpeewee

Limitations (hopefully resolved in a couple of weeks):

  • currently just aiomysql supported

  • untested transactions

More thorough testing is on the way.

Any feedback would be greatly appreciated!

Install

pip install aiopeewee

Usage

from aiopeewee import AioModel, AioMySQLDatabase
from peewee import CharField, TextField, DateTimeField
from peewee import ForeignKeyField, PrimaryKeyField


db = AioMySQLDatabase('test', host='127.0.0.1', port=3306,
                      user='root', password='')


class User(AioModel):
    username = CharField()

    class Meta:
        database = db


class Blog(AioModel):
    user = ForeignKeyField(User)
    title = CharField(max_length=25)
    content = TextField(default='')
    pub_date = DateTimeField(null=True)
    pk = PrimaryKeyField()

    class Meta:
        database = db


# create connection pool
await db.connect(loop)

# count
await User.select().count()

# insert
user = await User.create(username='kszucs')

# modify
user.username = 'krisztian'
await user.save()

# async iteration on blog set
[b.title async for b in user.blog_set.order_by(Blog.title)]

# close connection pool
await db.close()

# see more in the tests

Project details


Download files

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

Source Distribution

aiopeewee-0.3.0.tar.gz (11.1 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page