taskiq-asyncpg


Nametaskiq-asyncpg JSON
Version 0.3.2 PyPI version JSON
download
home_pageNone
SummaryAsyncpg and PostgreSQL integration for taskiq
upload_time2024-10-21 20:03:29
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseNone
keywords async asyncpg distributed postgresql result_backend taskiq tasks
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # TaskIQ - Asyncpg

TaskIQ-Asyncpg is a plugin for taskiq that adds a new result backend based on PostgreSQL and [Asyncpg](https://github.com/MagicStack/asyncpg).

## Installation
To use this project you must have installed core taskiq library:
```bash
pip install taskiq
```

This project can be installed using pip:
```bash
pip install taskiq-asyncpg
```

using poetry:
```bash
poetry add taskiq-asyncpg
```

using rye:
```bash
rye add taskiq-asyncpg
```

## Usage
Let's see the example with the redis broker and PostgreSQL Asyncpg result backend:
```python
# broker.py
import asyncio

from taskiq_redis import ListQueueBroker
from taskiq_asyncpg import AsyncpgResultBackend

asyncpg_result_backend = AsyncpgResultBackend(
    dsn="postgres://postgres:postgres@localhost:5432/postgres",
)

# Or you can use PubSubBroker if you need broadcasting
broker = ListQueueBroker(
    url="redis://localhost:6379",
    result_backend=asyncpg_result_backend,
)


@broker.task
async def best_task_ever() -> None:
    """Solve all problems in the world."""
    await asyncio.sleep(5.5)
    print("All problems are solved!")


async def main():
    await broker.startup()
    task = await best_task_ever.kiq()
    print(await task.wait_result())
    await broker.shutdown()


if __name__ == "__main__":
    asyncio.run(main())
```

## AsyncpgResultBackend configuration
- `dsn`: connection string to PostgreSQL.
- `keep_results`: flag to not remove results from Redis after reading.
- `table_name`: name of the table in PostgreSQL to store TaskIQ results.
- `field_for_task_id`: type of a field for `task_id`, you may need it if you want to have length of task_id more than 255 symbols.
- `serializer`: type of `TaskiqAsyncpgSerializer` default is `PickleSerializer`
- `**connect_kwargs`: additional connection parameters, you can read more about it in [Asyncpg](https://github.com/qaspen-python/asyncpg) repository.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "taskiq-asyncpg",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "async, asyncpg, distributed, postgresql, result_backend, taskiq, tasks",
    "author": null,
    "author_email": "Jefferson Venceslau <jeff.venceslau@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/1d/45/69fa76190e28add927ef220c7e92f06188ba5123108050a32a7c6a38c956/taskiq_asyncpg-0.3.2.tar.gz",
    "platform": null,
    "description": "# TaskIQ - Asyncpg\n\nTaskIQ-Asyncpg is a plugin for taskiq that adds a new result backend based on PostgreSQL and [Asyncpg](https://github.com/MagicStack/asyncpg).\n\n## Installation\nTo use this project you must have installed core taskiq library:\n```bash\npip install taskiq\n```\n\nThis project can be installed using pip:\n```bash\npip install taskiq-asyncpg\n```\n\nusing poetry:\n```bash\npoetry add taskiq-asyncpg\n```\n\nusing rye:\n```bash\nrye add taskiq-asyncpg\n```\n\n## Usage\nLet's see the example with the redis broker and PostgreSQL Asyncpg result backend:\n```python\n# broker.py\nimport asyncio\n\nfrom taskiq_redis import ListQueueBroker\nfrom taskiq_asyncpg import AsyncpgResultBackend\n\nasyncpg_result_backend = AsyncpgResultBackend(\n    dsn=\"postgres://postgres:postgres@localhost:5432/postgres\",\n)\n\n# Or you can use PubSubBroker if you need broadcasting\nbroker = ListQueueBroker(\n    url=\"redis://localhost:6379\",\n    result_backend=asyncpg_result_backend,\n)\n\n\n@broker.task\nasync def best_task_ever() -> None:\n    \"\"\"Solve all problems in the world.\"\"\"\n    await asyncio.sleep(5.5)\n    print(\"All problems are solved!\")\n\n\nasync def main():\n    await broker.startup()\n    task = await best_task_ever.kiq()\n    print(await task.wait_result())\n    await broker.shutdown()\n\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n```\n\n## AsyncpgResultBackend configuration\n- `dsn`: connection string to PostgreSQL.\n- `keep_results`: flag to not remove results from Redis after reading.\n- `table_name`: name of the table in PostgreSQL to store TaskIQ results.\n- `field_for_task_id`: type of a field for `task_id`, you may need it if you want to have length of task_id more than 255 symbols.\n- `serializer`: type of `TaskiqAsyncpgSerializer` default is `PickleSerializer`\n- `**connect_kwargs`: additional connection parameters, you can read more about it in [Asyncpg](https://github.com/qaspen-python/asyncpg) repository.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Asyncpg and PostgreSQL integration for taskiq",
    "version": "0.3.2",
    "project_urls": null,
    "split_keywords": [
        "async",
        " asyncpg",
        " distributed",
        " postgresql",
        " result_backend",
        " taskiq",
        " tasks"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1d4569fa76190e28add927ef220c7e92f06188ba5123108050a32a7c6a38c956",
                "md5": "989679ea3ddb791099bfed87631a94b5",
                "sha256": "4f02ba4be248ad3564804d473627365d499f073cc97062671650db2d78a5d5ae"
            },
            "downloads": -1,
            "filename": "taskiq_asyncpg-0.3.2.tar.gz",
            "has_sig": false,
            "md5_digest": "989679ea3ddb791099bfed87631a94b5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 10316,
            "upload_time": "2024-10-21T20:03:29",
            "upload_time_iso_8601": "2024-10-21T20:03:29.408307Z",
            "url": "https://files.pythonhosted.org/packages/1d/45/69fa76190e28add927ef220c7e92f06188ba5123108050a32a7c6a38c956/taskiq_asyncpg-0.3.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-21 20:03:29",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "taskiq-asyncpg"
}
        
Elapsed time: 0.36896s