Skip to main content

Asynchronous interface for peewee ORM powered by asyncio.

Project description

peewee-async

Asynchronous interface for peewee ORM powered by asyncio.

CI workflow PyPi Version Documentation Status

Important notes

  • Since version 0.6.0a only peewee 3.5+ is supported
  • If you still need Python 3.5 support use older versions, i.e. pip install peewee-async==0.7.2

Overview

  • Requires Python 3.6+
  • 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

The code below is using new Python 3.6 async / await syntax

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 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


Download files

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

Source Distribution

peewee-async-0.8.0.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

peewee_async-0.8.0-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file peewee-async-0.8.0.tar.gz.

File metadata

  • Download URL: peewee-async-0.8.0.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.1

File hashes

Hashes for peewee-async-0.8.0.tar.gz
Algorithm Hash digest
SHA256 3002a8d7c01067fa919b670a7c999e6df0e400844586aeafbfba9f57d4d1f7d2
MD5 703ca80110df0b27956472a3369b3815
BLAKE2b-256 3c642553d828b3809f06520b5737533b18e995902dbb4c1836732943ae33e947

See more details on using hashes here.

File details

Details for the file peewee_async-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: peewee_async-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.1

File hashes

Hashes for peewee_async-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e2bcf67706c165a69d338f944e635d3ab26fa70614d202a0dba81342d39c120e
MD5 60bde3c651da8e3fcd677a265fb0aab4
BLAKE2b-256 d29bb245bb3087192c0d8228b9c9dd92cd7ee7a1ff83358fc5b8f68b8ef88d47

See more details on using hashes here.

Supported by

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