celery-sqlalchemy
SQLAlchemy model serialization for celery. Supports SQLAlchemy 1.4 & 2.0.
Install
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 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.
from celery_sqlalchemy.celery import initialize as initialize_celery
from celery_sqlalchemy.json import JsonSerializer
# setup celery
celery = ...
# initialize celery-sqlalchemy
initialize_celery(celery, JsonSerializer())
# 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.
from celery_sqlalchemy.celery import initialize as initialize_celery
from celery_sqlalchemy.json import JsonSerializer
# setup celery
celery = ...
# initialize celery-sqlalchemy without the `apply_serializer` setting
initialize_celery(celery, JsonSerializer(), 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.
from celery_sqlalchemy.celery import initialize as initialize_celery
from celery_sqlalchemy.json import JsonSerializer
# setup celery
celery = ...
# initialize celery-sqlalchemy without the `apply_serializer` setting
initialize_celery(celery, JsonSerializer(), 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.6
- Extract celery support into its own module
- Remove
celery_sqlalchemy.initialize()
- 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
Release files for celery-sqlalchemy 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| celery_sqlalchemy-0.1.6.tar.gz | 11.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| celery_sqlalchemy-0.1.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.9 kB
Release files / celery_sqlalchemy-0.1.6.tar.gz
| Download URL | celery_sqlalchemy-0.1.6.tar.gz |
|---|---|
| Size | 11.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5d468272603e32e90af823c0bc0bf799b83739cd5151254a9a6f9f24b88ed9eb
|
|
BLAKE2b-256 checksum How to use checksums |
1017a3280b81bad1512e1e5f1f2771be548359544394f4e15a96249545098edc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.6.1 CPython/3.10.12 Linux/6.5.0-15-generic
|
Release files / celery_sqlalchemy-0.1.6-py3-none-any.whl
| Download URL | celery_sqlalchemy-0.1.6-py3-none-any.whl |
|---|---|
| Size | 14.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
17fbef965ba3031954eb6f353afb51634dc2350a52270d418dccc194ac86c6fc
|
|
BLAKE2b-256 checksum How to use checksums |
ef5d31f6095f5cac57306fe147aef33a58b239951402b51a9fde00c7e96c44b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.6.1 CPython/3.10.12 Linux/6.5.0-15-generic
|