{"id":28764980,"url":"https://github.com/klen/peewee-aio","last_synced_at":"2025-08-17T18:33:45.739Z","repository":{"id":41392306,"uuid":"403920239","full_name":"klen/peewee-aio","owner":"klen","description":"Async support for Peewee ORM","archived":false,"fork":false,"pushed_at":"2024-11-02T14:46:00.000Z","size":308,"stargazers_count":45,"open_issues_count":5,"forks_count":7,"subscribers_count":6,"default_branch":"develop","last_synced_at":"2024-11-02T15:03:12.539Z","etag":null,"topics":["asyncio","orm","peewee","peewee-orm","python","sql","trio"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/klen.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-09-07T09:32:32.000Z","updated_at":"2024-11-02T14:46:02.000Z","dependencies_parsed_at":"2023-01-31T03:16:06.981Z","dependency_job_id":null,"html_url":"https://github.com/klen/peewee-aio","commit_stats":null,"previous_names":[],"tags_count":56,"template":false,"template_full_name":null,"purl":"pkg:github/klen/peewee-aio","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klen%2Fpeewee-aio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klen%2Fpeewee-aio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klen%2Fpeewee-aio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klen%2Fpeewee-aio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/klen","download_url":"https://codeload.github.com/klen/peewee-aio/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klen%2Fpeewee-aio/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260336372,"owners_count":22993742,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asyncio","orm","peewee","peewee-orm","python","sql","trio"],"created_at":"2025-06-17T10:13:13.076Z","updated_at":"2025-08-17T18:33:45.721Z","avatar_url":"https://github.com/klen.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 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 \u003e= 3.9\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\n### Supported schemas\n\n- `aiomyql`\n- `aiomyql+pool`\n- `aiopg`\n- `aiopg+pool`\n- `asyncpg`\n- `asyncpg+pool`\n- `aioodbc`\n- `aioodbc+pool`\n- `aiosqlite`\n- `trio-mysql`\n- `triopg`\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklen%2Fpeewee-aio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fklen%2Fpeewee-aio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklen%2Fpeewee-aio/lists"}