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.10+
  • Has support for PostgreSQL via aiopg and psycopg3
  • Has support for MySQL via aiomysql
  • Has support for Sqlite via aiosqlite
  • Asynchronous analogues of peewee sync methods with prefix aio_
  • Drop-in replacement for sync code, sync will remain sync
  • Most basic operations are supported
  • Transactions support is present

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

Install

Install with pip for PostgreSQL aiopg backend:

pip install peewee-async[postgresql]

or for PostgreSQL psycopg3 backend:

pip install peewee-async[psycopg]

or for MySQL:

pip install peewee-async[mysql]

or for Sqlite:

pip install peewee-async[sqlite]

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 .[dev]

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-2.0.0.tar.gz (14.2 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-2.0.0-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: peewee_async-2.0.0.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for peewee_async-2.0.0.tar.gz
Algorithm Hash digest
SHA256 306daf2f91cc30bba66ac42252aca578de8188d4de12333a98cbb89eff43c702
MD5 8747d9cb5350a8392e406ede41950caf
BLAKE2b-256 2aa35f38d5ed0db22215c504b8124d09b669430edbb546fde478335702c143ea

See more details on using hashes here.

File details

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

File metadata

  • Download URL: peewee_async-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for peewee_async-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a514b58d6281790f1ff5c6c308fd6018e61cbe7631e569b2f097b687fc1b26bb
MD5 20f75a819a888e416af3c81a7c852940
BLAKE2b-256 7c5852121f6b2c4f8d4124997a9789d0cacef3b188ef8521457458e58d2cb259

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