A library for serializing Pydantic models in Celery tasks
Project description
Celery Pydantic
A library that provides seamless integration between Celery and Pydantic models, allowing you to serialize and deserialize Pydantic models in Celery tasks.
Installation
pip install celery-pydantic
Usage
from celery import Celery
from pydantic import BaseModel
from celery_pydantic import pydantic_celery
# Define your Pydantic model
class User(BaseModel):
name: str
age: int
# Create your Celery app
app = Celery('myapp', broker='amqp://')
# Configure the app to use Pydantic serialization
pydantic_celery(app)
# Use Pydantic models in your tasks
@app.task
def process_user(user: User):
return user.name
# Call the task with a Pydantic model
user = User(name="John", age=30)
result = process_user.delay(user)
Features
- Automatic serialization and deserialization of Pydantic models in Celery tasks
- Support for nested Pydantic models
- Maintains type safety throughout the task execution
- Compatible with Celery's result backend
Testing
To run the tests locally:
uv sync --all-extrasuv run pytest
Requirements
- Python 3.9+
- Celery 5.0+
- Pydantic 2.0+
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
celery_pydantic-1.0.1.tar.gz
(4.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file celery_pydantic-1.0.1.tar.gz.
File metadata
- Download URL: celery_pydantic-1.0.1.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b746bdf306a574ea9296441fc32d18e9f35cc6e5f07096ae03e422be2b5a54f
|
|
| MD5 |
2307e184b969c6e3174fc0539278aa75
|
|
| BLAKE2b-256 |
6eaa4d734614a34ceb214f971aa6940d9f7a74f4f1d4026ca2231ed3b5b8ad29
|
File details
Details for the file celery_pydantic-1.0.1-py3-none-any.whl.
File metadata
- Download URL: celery_pydantic-1.0.1-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ce1c0279fe2ea20055f1aa2323fb7069fdd8883b191710fedc726d38f249086
|
|
| MD5 |
40b80e26884c31b1f677770f2201146c
|
|
| BLAKE2b-256 |
ed15bea1b41c76f3e9c18fd6ec53f82df2802ce48d8b7f030b4f529d30b7d30b
|