# Peewee-AIO
Async support for [Peewee ORM](https://github.com/coleifer/peewee)
[![Tests Status](https://github.com/klen/peewee-aio/workflows/tests/badge.svg)](https://github.com/klen/peewee-aio/actions)
[![PYPI Version](https://img.shields.io/pypi/v/peewee-aio)](https://pypi.org/project/peewee-aio/)
[![Python Versions](https://img.shields.io/pypi/pyversions/peewee-aio)](https://pypi.org/project/peewee-aio/)
## Features
* Make [Peewee ORM](https://github.com/coleifer/peewee) to work async
* Supports PostgresQL, MySQL, SQLite
* Supports [asyncio](https://docs.python.org/3/library/asyncio.html) and
[trio](https://github.com/python-trio/trio)
* Contains types as well
* Drivers supported:
- [aiosqlite](https://github.com/omnilib/aiosqlite)
- [aiomysql](https://github.com/aio-libs/aiomysql)
- [aiopg](https://github.com/aio-libs/aiopg)
- [asyncpg](https://github.com/MagicStack/asyncpg)
- [triopg](https://github.com/python-trio/triopg)
- [trio_mysql](https://github.com/python-trio/trio-mysql)
## Requirements
* python >= 3.8
## Installation
**peewee-aio** should be installed using pip:
```shell
$ pip install peewee-aio
```
You can install optional database drivers with:
```shell
$ pip install peewee-aio[aiosqlite] # for SQLite (asyncio)
$ pip install peewee-aio[aiomysql] # for MySQL (asyncio)
$ pip install peewee-aio[aiopg] # for Postgresql (asyncio)
$ pip install peewee-aio[asyncpg] # for Postgresql (asyncio)
$ pip install peewee-aio[trio_mysql] # for MySQL (trio)
$ pip install peewee-aio[triopg] # for PostgresQL (trio)
```
### Quickstart
```python
import peewee
from peewee_aio import Manager, AIOModel, fields
manager = Manager('aiosqlite:///:memory:')
@manager.register
class Role(AIOModel):
# Pay attention that we are using fields from Peewee-AIO for better typing support
id = fields.AutoField()
name = fields.CharField()
@manager.register
class User(AIOModel):
# Pay attention that we are using fields from Peewee-AIO for better typing support
id = fields.AutoField()
name = fields.CharField()
role = fields.ForeignKeyField(Role)
async def handler():
# Initialize the database's pool (optional)
async with manager:
# Acquire a connection
async with manager.connection():
# Create the tables in database
await Role.create_table()
await User.create_table()
# Create a record
role = await Role.create(name='user')
assert role
assert role.id # role.id contains correct string type
user = await User.create(name="Andrey", role=role)
assert user
assert user.id
role = await user.role # Load role from DB using the foreign key
assert role # role has a correct Role Type
# Iterate through records
async for user in User.select(User, Role).join(Role):
assert user # user has a corrent User Type
assert user.id
role = await user.role # No DB query here, because the fk is preloaded
# Change records
user.name = "Dmitry"
await user.save()
# Update records
await User.update({"name": "Anonimous"}).where(User.id == user.id)
# Delete records
await User.delete().where(User.id == user.id)
# Drop the tables in database
await User.drop_table()
await Role.drop_table()
# Run the handler with your async library
import asyncio
asyncio.run(handler())
```
## Usage
TODO
### Sync usage
The library still supports sync mode (use `manager.allow_sync`):
```python
class Test(peewee.Model):
data = peewee.CharField()
with manager.allow_sync():
Test.create_table()
Test.create(data='test')
assert Test.select().count()
Test.update(data='new-test').execute()
```
### Get prefetched relations
TODO
```python
# We prefetched roles here
async for user in User.select(User, Role).join(Role):
role = user.fetch(User.role) # get role from user relations cache
```
## Bug tracker
If you have any suggestions, bug reports or annoyances please report them to
the issue tracker at https://github.com/klen/peewee-aio/issues
## Contributing
Development of the project happens at: https://github.com/klen/peewee-aio
## License
Licensed under a [MIT License](http://opensource.org/licenses/MIT)
Raw data
{
"_id": null,
"home_page": "https://github.com/klen/peewee-aio",
"name": "peewee-aio",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8,<4.0",
"maintainer_email": "",
"keywords": "peewee,asyncio,trio,orm",
"author": "Kirill Klenov",
"author_email": "horneds@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/19/98/23fef2e91d024d066b9ccca9908acadb0c8e673aadcb71a079652eacd8be/peewee_aio-1.7.4.tar.gz",
"platform": null,
"description": "# Peewee-AIO\n\nAsync support for [Peewee ORM](https://github.com/coleifer/peewee)\n\n[![Tests Status](https://github.com/klen/peewee-aio/workflows/tests/badge.svg)](https://github.com/klen/peewee-aio/actions)\n[![PYPI Version](https://img.shields.io/pypi/v/peewee-aio)](https://pypi.org/project/peewee-aio/)\n[![Python Versions](https://img.shields.io/pypi/pyversions/peewee-aio)](https://pypi.org/project/peewee-aio/)\n\n## Features\n\n* Make [Peewee ORM](https://github.com/coleifer/peewee) to work async\n* Supports PostgresQL, MySQL, SQLite\n* Supports [asyncio](https://docs.python.org/3/library/asyncio.html) and\n [trio](https://github.com/python-trio/trio)\n* Contains types as well\n* Drivers supported:\n - [aiosqlite](https://github.com/omnilib/aiosqlite)\n - [aiomysql](https://github.com/aio-libs/aiomysql)\n - [aiopg](https://github.com/aio-libs/aiopg)\n - [asyncpg](https://github.com/MagicStack/asyncpg)\n - [triopg](https://github.com/python-trio/triopg)\n - [trio_mysql](https://github.com/python-trio/trio-mysql)\n\n\n## Requirements\n\n* python >= 3.8\n\n## Installation\n\n**peewee-aio** should be installed using pip:\n\n```shell\n$ pip install peewee-aio\n```\n\nYou can install optional database drivers with:\n\n```shell\n$ pip install peewee-aio[aiosqlite] # for SQLite (asyncio)\n$ pip install peewee-aio[aiomysql] # for MySQL (asyncio)\n$ pip install peewee-aio[aiopg] # for Postgresql (asyncio)\n$ pip install peewee-aio[asyncpg] # for Postgresql (asyncio)\n$ pip install peewee-aio[trio_mysql] # for MySQL (trio)\n$ pip install peewee-aio[triopg] # for PostgresQL (trio)\n```\n\n### Quickstart\n\n```python\n import peewee\n from peewee_aio import Manager, AIOModel, fields\n\n manager = Manager('aiosqlite:///:memory:')\n\n @manager.register\n class Role(AIOModel):\n # Pay attention that we are using fields from Peewee-AIO for better typing support\n id = fields.AutoField()\n name = fields.CharField()\n\n @manager.register\n class User(AIOModel):\n\n # Pay attention that we are using fields from Peewee-AIO for better typing support\n id = fields.AutoField()\n name = fields.CharField()\n role = fields.ForeignKeyField(Role)\n\n async def handler():\n\n # Initialize the database's pool (optional)\n async with manager:\n\n # Acquire a connection\n async with manager.connection():\n\n # Create the tables in database\n await Role.create_table()\n await User.create_table()\n\n # Create a record\n role = await Role.create(name='user')\n assert role\n assert role.id # role.id contains correct string type\n user = await User.create(name=\"Andrey\", role=role)\n assert user\n assert user.id\n role = await user.role # Load role from DB using the foreign key\n assert role # role has a correct Role Type\n\n # Iterate through records\n async for user in User.select(User, Role).join(Role):\n assert user # user has a corrent User Type\n assert user.id\n role = await user.role # No DB query here, because the fk is preloaded\n\n # Change records\n user.name = \"Dmitry\"\n await user.save()\n\n # Update records\n await User.update({\"name\": \"Anonimous\"}).where(User.id == user.id)\n\n # Delete records\n await User.delete().where(User.id == user.id)\n\n # Drop the tables in database\n await User.drop_table()\n await Role.drop_table()\n\n # Run the handler with your async library\n import asyncio\n\n asyncio.run(handler())\n```\n\n## Usage\n\nTODO\n\n### Sync usage\n\nThe library still supports sync mode (use `manager.allow_sync`):\n\n```python\n\nclass Test(peewee.Model):\n data = peewee.CharField()\n\nwith manager.allow_sync():\n Test.create_table()\n Test.create(data='test')\n assert Test.select().count()\n Test.update(data='new-test').execute()\n\n```\n\n\n### Get prefetched relations\n\nTODO\n\n```python\n# We prefetched roles here\nasync for user in User.select(User, Role).join(Role):\n role = user.fetch(User.role) # get role from user relations cache\n\n```\n\n## Bug tracker\n\nIf you have any suggestions, bug reports or annoyances please report them to\nthe issue tracker at https://github.com/klen/peewee-aio/issues\n\n\n## Contributing\n\nDevelopment of the project happens at: https://github.com/klen/peewee-aio\n\n\n## License\n\nLicensed under a [MIT License](http://opensource.org/licenses/MIT)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Async support for Peewee ORM",
"version": "1.7.4",
"project_urls": {
"Homepage": "https://github.com/klen/peewee-aio",
"Repository": "https://github.com/klen/peewee-aio"
},
"split_keywords": [
"peewee",
"asyncio",
"trio",
"orm"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f05207cf77901d138736a2904bf2b45ba4687dae9bdb1ea0cfc594d0a0f7d07d",
"md5": "42eb168146fa97e5e8efb4505ec3a832",
"sha256": "e6f110213913b9428960b6ac4594bb311f0a66ee3fd30e3f7994520bb57b5d70"
},
"downloads": -1,
"filename": "peewee_aio-1.7.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "42eb168146fa97e5e8efb4505ec3a832",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8,<4.0",
"size": 15157,
"upload_time": "2023-11-18T23:21:03",
"upload_time_iso_8601": "2023-11-18T23:21:03.613427Z",
"url": "https://files.pythonhosted.org/packages/f0/52/07cf77901d138736a2904bf2b45ba4687dae9bdb1ea0cfc594d0a0f7d07d/peewee_aio-1.7.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "199823fef2e91d024d066b9ccca9908acadb0c8e673aadcb71a079652eacd8be",
"md5": "dc2e234d386be8411fe7d6c65c5662bb",
"sha256": "dddd2326bec0ecb9ae402579f64acfbae97f9a5d505077c53aa33870649eac0b"
},
"downloads": -1,
"filename": "peewee_aio-1.7.4.tar.gz",
"has_sig": false,
"md5_digest": "dc2e234d386be8411fe7d6c65c5662bb",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8,<4.0",
"size": 14689,
"upload_time": "2023-11-18T23:21:05",
"upload_time_iso_8601": "2023-11-18T23:21:05.671463Z",
"url": "https://files.pythonhosted.org/packages/19/98/23fef2e91d024d066b9ccca9908acadb0c8e673aadcb71a079652eacd8be/peewee_aio-1.7.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-18 23:21:05",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "klen",
"github_project": "peewee-aio",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "peewee-aio"
}