aio-peewee
DeprecationWarning
The package is deprecated. Please use peewee-aio instead.
—
aio-peewee – Peewee support for async frameworks (Asyncio, Trio, Curio)
The library doesn’t make peewee work async, but allows you to use Peewee with your asyncio based libraries correctly.
Features
Tasks Safety. The library tracks of the connection state using Task-local storage, making the Peewee Database object safe to use with multiple tasks inside a loop.
Async management of connections for Peewee Connections Pool
Requirements
python >= 3.8
Installation
aio-peewee should be installed using pip:
pip install aio-peewee
QuickStart
from aiopeewee import db_url
db = db_url.connect('postgres+async://locahost:5432/database')
async def main(id=1):
async with db:
item = Model.get(Model.id == 1)
return item.name
Usage
Initialization
from aiopeewee import PostgresqlDatabaseAsync, SqliteDatabaseAsync, MySQLDatabaseAsync, CockroachDatabaseAsync
db = PostgresqlDatabaseAsync('my_app', user='app', password='db_password', host='10.1.0.8', port=3306)
Async Connect
# Manual
async def main():
await db.connect_async()
# ...
await db.close_async()
# Context manager
async def main():
async with db:
# ...
Connection Pooling
from aiopeewee import PooledPostgresqlDatabaseAsync, PooledSqliteDatabaseAsync, PooledMySQLDatabaseAsync, PooledCockroachDatabaseAsync
db = PooledPostgresqlDatabaseAsync('my_database', max_connections=8, stale_timeout=300, user='postgres')
Database URL
from aiopeewee import db_url
db0 = db_url.connect('cockroachdb+async://localhost/db', **db_params)
db1 = db_url.connect('cockroachdb+pool+async://localhost/db', **db_params)
db2 = db_url.connect('mysql+async://localhost/db', **db_params)
db3 = db_url.connect('mysql+pool+async://localhost/db', **db_params)
db4 = db_url.connect('postgres+async://localhost/db', **db_params)
db5 = db_url.connect('postgres+pool+async://localhost/db', **db_params)
db6 = db_url.connect('sqlite+async://localhost/db', **db_params)
db7 = db_url.connect('sqlite+pool+async://localhost/db', **db_params)
db8 = db_url.connect('sqliteexc+async://localhost/db', **db_params)
db9 = db_url.connect('sqliteexc+pool+async://localhost/db', **db_params)
ASGI Middleware
import datetime as dt
from asgi_tools import App
from aiopeewee import PeeweeASGIPlugin
import peewee as pw
db = PeeweeASGIPlugin(url='sqlite+async:///db.sqlite')
@db.register
class Visit(pw.Model):
created = pw.DateTimeField(default=dt.datetime.utcnow())
address = pw.CharField()
db.create_tables()
app = App()
@app.route('/')
async def visits_json(request):
"""Store the visit and load latest 10 visits."""
Visit.create(address=request.client[0])
return [{
'id': v.id, 'address': v.address, 'timestamp': round(v.created.timestamp()),
} for v in Visit.select().order_by(Visit.id.desc()).limit(10)]
app = db.middleware(app)
Curio
aio-peewee uses contextvars to store db connections. So you have to enable contextvars for Curio: https://curio.readthedocs.io/en/latest/howto.html#how-do-you-use-contextvars
Bug tracker
If you have any suggestions, bug reports or annoyances please report them to the issue tracker at https://github.com/klen/aio-peewee/issues
Contributing
Development of the project happens at: https://github.com/klen/aio-peewee
License
Licensed under a MIT license.
Metadata
Release files for aio-peewee 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aio-peewee-0.4.1.tar.gz | 7.4 kB | Without provenance | Details for aio-peewee-0.4.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aio_peewee-0.4.1-py3-none-any.whl | Python 3 | none | any | Details for aio_peewee-0.4.1-py3-none-any.whl |
Total release size: 15.3 kB
Release files / aio-peewee-0.4.1.tar.gz
| Download URL | aio-peewee-0.4.1.tar.gz |
|---|---|
| Size | 7.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8f043d8475da0e26090ee65f051e5a2d81f107d8695275905afe6d4d391dff8e
|
|
BLAKE2b-256 checksum How to use checksums |
3bfb44331a60813a1a4934d845fea327b89115c7632749d2d597ba9a52d84e4e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.15
|
Release files / aio_peewee-0.4.1-py3-none-any.whl
| Download URL | aio_peewee-0.4.1-py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
843141c40d0d440efef9c2eb12f956c6f8beead8cc6e8b454bf8be438d7d1ff3
|
|
BLAKE2b-256 checksum How to use checksums |
e5a5da2b48bff9d873cf3e62ee94434efb88b5554b566f9fe907eead3670ce6c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.15
|
Security for aio-peewee 0.4.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.