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

Overview

  • Requires Python 3.8+
  • Has support for PostgreSQL via aiopg
  • Has support for MySQL via aiomysql
  • Asynchronous analogues of peewee sync methods with prefix aio_
  • Drop-in replacement for sync code, sync will remain sync
  • Basic operations are supported
  • Transactions support is present

The complete documentation:
http://peewee-async-lib.readthedocs.io

Install

Install with pip for PostgreSQL:

pip install peewee-async[postgresql]

or for MySQL:

pip install peewee-async[mysql]

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.PooledPostgresqlDatabase(
    database='db_name',
    user='user',
    host='127.0.0.1',
    port='5432',
    password='password',
)

class TestModel(peewee_async.AioModel):
    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()

# No need for sync anymore!

database.set_allow_sync(False)

async def handler():
    await TestModel.aio_create(text="Not bad. Watch this, I'm async!")
    all_objects = await TestModel.select().aio_execute()
    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 database.allow_sync():
    TestModel.drop_table(True)

# Expected output:
# Yo, I can do it sync!
# Not bad. Watch this, I'm async!

More examples

Check the ./examples directory for more.

Documentation

http://peewee-async-lib.readthedocs.io

http://peewee-async.readthedocs.io - DEPRECATED

Developing

Install dependencies using pip:

pip install -e .[develop]

Or using poetry:

poetry 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


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-1.0.0.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

peewee_async-1.0.0-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file peewee_async-1.0.0.tar.gz.

File metadata

  • Download URL: peewee_async-1.0.0.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.8 Linux/5.15.0-117-generic

File hashes

Hashes for peewee_async-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3c907367b9af93fc5d3fc42415a18749ff61101b775a11aa25409cb9685d580a
MD5 a326e0fa0feeb27bc1934d886fde5217
BLAKE2b-256 eedbf17fe94a681441c6d285c30549251cf75f5887b6c2b4318e9406b7ae07d4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: peewee_async-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.8 Linux/5.15.0-117-generic

File hashes

Hashes for peewee_async-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4f21ffb53179036d08340f94e94af728aa96b2bf9b2886a4ecd4bf6522e37781
MD5 2d838616481988f83caa6afd1b35e8c9
BLAKE2b-256 bf37f3cc82934d121fb8f3672d494711147bcc321803ec5190c05434a68a5e37

See more details on using hashes here.

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