# celery-sqlalchemy
SQLAlchemy model serialization for celery. Supports SQLAlchemy 1.4 & 2.0.
### Install
```sh
pip install celery-sqlalchemy
```
### How does it work?
Any model or list of models passed to a celery task as a direct argument will be
serialized/deserialized by `celery-sqlalchemy`.
### Behind the scenes
The [orjson](https://github.com/ijl/orjson) library is used behind the scenes to handle
serialization of commonly used Python types.
### Usage
By default `celery-sqlalchemy` will configure Celery to use the `json+sqlalchemy`
content type for all tasks and no further configuration is needed.
```python
from celery_sqlalchemy import initialize
# setup celery
celery = ...
# initialize celery-sqlalchemy
initialize(celery)
# dispatch a task
author = "Alan Watts"
title = "Become What You Are"
task.delay(Model(author=author, title=title))
```
### Using the json+sqlalchemy content type in combination with other content types
The first way of doing this is by specifying the `json+sqlalchemy` content type as
the default task serializer.
```python
from celery_sqlalchemy import initialize
# setup celery
celery = ...
# initialize celery-sqlalchemy without the `apply_serializer` setting
initialize(celery, apply_serializer=False)
# combine the json+sqlalchemy content type with your other content types
celery.conf.accept_content = ["json+sqlalchemy", "your content type"]
celery.conf.result_accept_content = ["json+sqlalchemy", "your content type"]
# set the default task serializer
celery.conf.task_serializer = "json+sqlalchemy"
# dispatch a model task
author = "Alan Watts"
title = "Become What You Are"
task.delay(Model(author=author, title=title))
# dispatch a task using another content type
task.apply_async((author, title), serializer="your content type")
```
The other way of doing this is by not specifying the default task serializer, and
instead using `apply_async()` to dispatch all tasks.
```python
from celery_sqlalchemy import initialize
# setup celery
celery = ...
# initialize celery-sqlalchemy without the `apply_serializer` setting
initialize(celery, apply_serializer=False)
# combine the json+sqlalchemy content type with your other content types
celery.conf.accept_content = ["json+sqlalchemy", "your content type"]
celery.conf.result_accept_content = ["json+sqlalchemy", "your content type"]
# dispatch a model task
author = "Alan Watts"
title = "Become What You Are"
task.apply_async((Model(author=author, title=title),), serializer="json+sqlalchemy")
# dispatch a task using another content type
task.apply_async((author, title), serializer="your content type")
```
### Changelog
- **0.1.5**
- Bump sqlalchemy dependency
- **0.1.4**
- Bug fix: schema model may already be converted to model instance when chaining
- **0.1.3**
- Check list type when converting json back to argument
- **0.1.2**
- Add py.typed for mypy
- **0.1.1**
- Add support for SQLAlchemy 1.4
- **0.1.0**
- Initial version with support for common Python types
Raw data
{
"_id": null,
"home_page": "https://github.com/seankerr/py-celery-sqlalchemy",
"name": "celery-sqlalchemy",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.9,<4.0",
"maintainer_email": "",
"keywords": "celery,sqlalchemy,serialization",
"author": "Sean Kerr",
"author_email": "sean@code-box.org",
"download_url": "https://files.pythonhosted.org/packages/00/d4/e37f43aae16d1ac4a5de04f78c014c45c681ea210d0f4df35ed87b12f40e/celery_sqlalchemy-0.1.5.tar.gz",
"platform": null,
"description": "# celery-sqlalchemy\n\nSQLAlchemy model serialization for celery. Supports SQLAlchemy 1.4 & 2.0.\n\n### Install\n\n```sh\npip install celery-sqlalchemy\n```\n\n### How does it work?\n\nAny model or list of models passed to a celery task as a direct argument will be\nserialized/deserialized by `celery-sqlalchemy`.\n\n### Behind the scenes\n\nThe [orjson](https://github.com/ijl/orjson) library is used behind the scenes to handle\nserialization of commonly used Python types.\n\n### Usage\n\nBy default `celery-sqlalchemy` will configure Celery to use the `json+sqlalchemy`\ncontent type for all tasks and no further configuration is needed.\n\n```python\nfrom celery_sqlalchemy import initialize\n\n# setup celery\ncelery = ...\n\n# initialize celery-sqlalchemy\ninitialize(celery)\n\n# dispatch a task\nauthor = \"Alan Watts\"\ntitle = \"Become What You Are\"\n\ntask.delay(Model(author=author, title=title))\n```\n\n### Using the json+sqlalchemy content type in combination with other content types\n\nThe first way of doing this is by specifying the `json+sqlalchemy` content type as\nthe default task serializer.\n\n```python\nfrom celery_sqlalchemy import initialize\n\n# setup celery\ncelery = ...\n\n# initialize celery-sqlalchemy without the `apply_serializer` setting\ninitialize(celery, apply_serializer=False)\n\n# combine the json+sqlalchemy content type with your other content types\ncelery.conf.accept_content = [\"json+sqlalchemy\", \"your content type\"]\ncelery.conf.result_accept_content = [\"json+sqlalchemy\", \"your content type\"]\n\n# set the default task serializer\ncelery.conf.task_serializer = \"json+sqlalchemy\"\n\n# dispatch a model task\nauthor = \"Alan Watts\"\ntitle = \"Become What You Are\"\n\ntask.delay(Model(author=author, title=title))\n\n# dispatch a task using another content type\ntask.apply_async((author, title), serializer=\"your content type\")\n```\n\nThe other way of doing this is by not specifying the default task serializer, and\ninstead using `apply_async()` to dispatch all tasks.\n\n```python\nfrom celery_sqlalchemy import initialize\n\n# setup celery\ncelery = ...\n\n# initialize celery-sqlalchemy without the `apply_serializer` setting\ninitialize(celery, apply_serializer=False)\n\n# combine the json+sqlalchemy content type with your other content types\ncelery.conf.accept_content = [\"json+sqlalchemy\", \"your content type\"]\ncelery.conf.result_accept_content = [\"json+sqlalchemy\", \"your content type\"]\n\n# dispatch a model task\nauthor = \"Alan Watts\"\ntitle = \"Become What You Are\"\n\ntask.apply_async((Model(author=author, title=title),), serializer=\"json+sqlalchemy\")\n\n# dispatch a task using another content type\ntask.apply_async((author, title), serializer=\"your content type\")\n```\n\n### Changelog\n\n- **0.1.5**\n - Bump sqlalchemy dependency\n- **0.1.4**\n - Bug fix: schema model may already be converted to model instance when chaining\n- **0.1.3**\n - Check list type when converting json back to argument\n- **0.1.2**\n - Add py.typed for mypy\n- **0.1.1**\n - Add support for SQLAlchemy 1.4\n- **0.1.0**\n - Initial version with support for common Python types\n",
"bugtrack_url": null,
"license": "BSD-3-Clause",
"summary": "SQLAlchemy model serialization for celery.",
"version": "0.1.5",
"project_urls": {
"Homepage": "https://github.com/seankerr/py-celery-sqlalchemy",
"Repository": "https://github.com/seankerr/py-celery-sqlalchemy"
},
"split_keywords": [
"celery",
"sqlalchemy",
"serialization"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4460f09b97ccfb2a3b13e4d1fc8b6fea19b0157ade11c82910884d5c3bf6629f",
"md5": "fae8412bcf0d34822544c4068f07432a",
"sha256": "72e4c54582899e82c0fa08dc4c68b1d8c084cfcc8bb8d6b76d20218240f824d6"
},
"downloads": -1,
"filename": "celery_sqlalchemy-0.1.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "fae8412bcf0d34822544c4068f07432a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9,<4.0",
"size": 13288,
"upload_time": "2023-10-23T16:22:40",
"upload_time_iso_8601": "2023-10-23T16:22:40.500035Z",
"url": "https://files.pythonhosted.org/packages/44/60/f09b97ccfb2a3b13e4d1fc8b6fea19b0157ade11c82910884d5c3bf6629f/celery_sqlalchemy-0.1.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "00d4e37f43aae16d1ac4a5de04f78c014c45c681ea210d0f4df35ed87b12f40e",
"md5": "74e3e2f98bead7550ec297dd4b31f736",
"sha256": "81e04720cad2bcb188db92ccdfa0465c110b76e0edce6cd8806e2dfe30e72b94"
},
"downloads": -1,
"filename": "celery_sqlalchemy-0.1.5.tar.gz",
"has_sig": false,
"md5_digest": "74e3e2f98bead7550ec297dd4b31f736",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9,<4.0",
"size": 10696,
"upload_time": "2023-10-23T16:22:42",
"upload_time_iso_8601": "2023-10-23T16:22:42.208402Z",
"url": "https://files.pythonhosted.org/packages/00/d4/e37f43aae16d1ac4a5de04f78c014c45c681ea210d0f4df35ed87b12f40e/celery_sqlalchemy-0.1.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-23 16:22:42",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "seankerr",
"github_project": "py-celery-sqlalchemy",
"travis_ci": false,
"coveralls": true,
"github_actions": false,
"lcname": "celery-sqlalchemy"
}