Async support for Peewee ORM
- Make Peewee ORM to work async
- Supports PostgresQL, MySQL, SQLite
- Supports asyncio and trio
- Drivers supported:
- python >= 3.7
peewee-aio should be installed using pip:
$ pip install peewee-aio
You can install optional database drivers with:
$ pip install peewee-aio[aiosqlite]
$ pip install peewee-aio[aiomysql]
$ pip install peewee-aio[aiopg]
$ pip install peewee-aio[asyncpg]
$ pip install peewee-aio[trio_mysql]
$ pip install peewee-aio[triopg]
import peewee
from peewee_aio import Manager
manager = Manager('aiosqlite:///:memory:')
class TestModel(manager.Model):
text = peewee.CharField()
async def handler():
# Initialize the database's pool (optional)
async with manager:
# Acquire a connection
async with manager.connection():
# Create the table in database
await TestModel.create_table()
# Create a record
test = await TestModel.create(text="I'm working!")
assert test
assert test.id
# Iterate through records
async for test in TestModel.select():
assert test
assert test.id
# Change records
test.text = "I'm changed"
await test.save()
# Update records
await TestModel.update({'text': "I'm updated!"}).where(TestModel.id == test.id)
# Delete records
await TestModel.delete().where(TestModel.id == test.id)
# Drop the table in database
await TestModel.drop_table()
# Run the handler with your async library
import asyncio
asyncio.run(handler())
TODO
If you have any suggestions, bug reports or annoyances please report them to the issue tracker at https://github.com/klen/peewee-aio/issues
Development of the project happens at: https://github.com/klen/peewee-aio
Licensed under a MIT License