peewee-aio


Namepeewee-aio JSON
Version 2.0.0 PyPI version JSON
download
home_pagehttps://github.com/klen/peewee-aio
SummaryAsync support for Peewee ORM
upload_time2024-11-02 14:47:30
maintainerNone
docs_urlNone
authorKirill Klenov
requires_python<4.0,>=3.9
licenseMIT
keywords peewee asyncio trio orm
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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.9

## 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

### Supported schemas

- `aiomyql`
- `aiomyql+pool`
- `aiopg`
- `aiopg+pool`
- `asyncpg`
- `asyncpg+pool`
- `aioodbc`
- `aioodbc+pool`
- `aiosqlite`
- `trio-mysql`
- `triopg`

### 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": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": "peewee, asyncio, trio, orm",
    "author": "Kirill Klenov",
    "author_email": "horneds@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/f0/95/8ec32ea9b6b4799d2273f1f9de0d6459b97677f5f99b2cf15d7896bf4822/peewee_aio-2.0.0.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.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",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Async support for Peewee ORM",
    "version": "2.0.0",
    "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": "fa5553e8862372e5f67c34d264df11104fdb563808b2ece69a441e00fe48f89b",
                "md5": "a94022d229ceb8fa33799baa8392a95e",
                "sha256": "e58ec7b414a7cecfe00e3059784c3ed0d90575e0dee630e69bc8644075878f68"
            },
            "downloads": -1,
            "filename": "peewee_aio-2.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a94022d229ceb8fa33799baa8392a95e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 15181,
            "upload_time": "2024-11-02T14:47:29",
            "upload_time_iso_8601": "2024-11-02T14:47:29.532554Z",
            "url": "https://files.pythonhosted.org/packages/fa/55/53e8862372e5f67c34d264df11104fdb563808b2ece69a441e00fe48f89b/peewee_aio-2.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f0958ec32ea9b6b4799d2273f1f9de0d6459b97677f5f99b2cf15d7896bf4822",
                "md5": "ec7eada76a6d2ffaf3c1fb2e22b2879f",
                "sha256": "408b8d8ee7dc02e7eeafb4f3f0a35dd8b2819bb59ad14c76697ce99e8d2b7832"
            },
            "downloads": -1,
            "filename": "peewee_aio-2.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "ec7eada76a6d2ffaf3c1fb2e22b2879f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 14809,
            "upload_time": "2024-11-02T14:47:30",
            "upload_time_iso_8601": "2024-11-02T14:47:30.618963Z",
            "url": "https://files.pythonhosted.org/packages/f0/95/8ec32ea9b6b4799d2273f1f9de0d6459b97677f5f99b2cf15d7896bf4822/peewee_aio-2.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-02 14:47:30",
    "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"
}
        
Elapsed time: 0.48556s