Skip to content

horpto/peewee-async

 
 

Repository files navigation

peewee-async

Asynchronous interface for peewee ORM powered by asyncio.

Documentation

http://peewee-async.readthedocs.org

Install

Works on Python 3.3+ and PostgreSQL database.

Install with pip:

pip install peewee-async

Quickstart

Create test PostgreSQL database, i.e. 'test' for running this snippet:

import asyncio
import peewee
import peewee_async

database = peewee_async.PostgresqlDatabase('test')
loop = asyncio.get_event_loop()

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

    class Meta:
        database = database

# Create table synchronously!
TestModel.create_table(True)
# This is optional: close sync connection
database.close()

@asyncio.coroutine
def my_handler():
    TestModel.create(text="Yo, I can do it sync!")
    yield from peewee_async.create_object(TestModel, text="Not bad. Watch this, I'm async!")
    all_objects = yield from peewee_async.execute(TestModel.select())
    for obj in all_objects:
        print(obj.text)

loop.run_until_complete(database.connect_async(loop=loop))
loop.run_until_complete(my_handler())

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.

About

Asynchronous interface for peewee ORM powered by asyncio

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%