Skip to main content

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')

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

  1. uv sync --all-extras
  2. uv run pytest

Requirements

  • Python 3.9+
  • Celery 5.0+
  • Pydantic 2.0+

License

MIT License

Project details


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-0.1.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

celery_pydantic-0.1.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file celery_pydantic-0.1.0.tar.gz.

File metadata

  • Download URL: celery_pydantic-0.1.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for celery_pydantic-0.1.0.tar.gz
Algorithm Hash digest
SHA256 79c542981886919540fcbc5c1f06b2b7cb24e82d3ef49b3e155d678f36fffce9
MD5 e6001f0926475897be935d74fcddca9e
BLAKE2b-256 2462691c455c536443d6fdfe1b043bbdb4cbc89a420fb3e5ef42ca12fbeb7f02

See more details on using hashes here.

File details

Details for the file celery_pydantic-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for celery_pydantic-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2b34313807181f9ea504603708fe05cbfa9f66ba639dada337349c9fd506df0b
MD5 428c7c7689bfe198c729d0572ed6968a
BLAKE2b-256 f8bd166ea8bc42ed8c88309bd8073652697e2997d18d99a5e4e3f6a2f26b890a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page