Asynchronous interface for peewee ORM powered by asyncio.
Project description
peewee-async
Asynchronous interface for peewee ORM powered by asyncio.
Overview
- Requires Python 3.7+
- Has support for PostgreSQL via aiopg
- Has support for MySQL via aiomysql
- Single point for high-level async API
- Drop-in replacement for sync code, sync will remain sync
- Basic operations are supported
- Transactions support is present, yet not heavily tested
The complete documentation:
http://peewee-async.readthedocs.io
Install
Install with pip
for PostgreSQL:
pip install --pre peewee-async; pip install aiopg
or for MySQL:
pip install --pre peewee-async; pip install aiomysql
Quickstart
Create 'test' PostgreSQL database for running this snippet:
createdb -E utf-8 test
import asyncio
import peewee
import peewee_async
# Nothing special, just define model and database:
database = peewee_async.PostgresqlDatabase(
database='db_name',
user='user',
host='127.0.0.1',
port='5432',
password='password'
)
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!
Documentation
http://peewee-async.readthedocs.io
Developing
Install dependencies:
pip install -e .[develop]
Run databases:
docker-compose up -d
Run tests:
pytest tests -v -s
Discuss
You are welcome to add discussion topics or bug reports to tracker on GitHub: https://github.com/05bit/peewee-async/issues
License
Copyright (c) 2014, Alexey Kinev rudy@05bit.com
Licensed under The MIT License (MIT), see LICENSE file for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for peewee_async-0.8.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e08a09fa9f104c352342abaf7f5bff6327490f5b931552f27bc1aac26b58ad44 |
|
MD5 | 75efb6a07634e041a725d43a2bcba8aa |
|
BLAKE2b-256 | 15276c389399d7b094ce87e558517b943545ec8fa3167b858fa760263b76f819 |