Skip to main content

Pikadantic provides robust data validation for RabbitMQ messaging

Project description

Pikadantic

CI pypi versions MIT License

Pikadantic is a Python library that integrates Pika with Pydantic to provide robust data validation for RabbitMQ messaging.

🚀 Why Pikadantic?

  • Seamless Integration: Combines Pika's messaging capabilities with Pydantic's data validation.
  • Type Safety: Leverages Python's type hints for clear and enforceable message schemas.
  • Data Integrity: Validates messages before sending or processing, reducing runtime errors.

📦 Installation

Install Pikadantic using pip:

pip install pikadantic

🧩 Example Usage

Here's a simple example of how to use Pikadantic with RabbitMQ:

from pika import BlockingConnection, ConnectionParameters
from pydantic import BaseModel
from pikadantic import validate_body

# Define your message model
class UserMessage(BaseModel):
    user_id: int
    name: str
    email: str

# Create a connection
connection = BlockingConnection(ConnectionParameters('localhost'))
channel = connection.channel()

# Define your message handler with validation
@validate_body(UserMessage)
def handle_message(channel, method, properties, body):
    # The body is already validated against UserMessage model
    print(f"Received message: {body}")

# Alternative approach using only_model=True
@validate_body(UserMessage, only_model=True)
def handle_message_simplified(message: UserMessage):
    # You get the validated model directly
    print(f"User {message.name} with ID {message.user_id}")

# Set up consumer
channel.basic_consume(
    queue='user_queue',
    on_message_callback=handle_message
)

# Start consuming
channel.start_consuming()

In this example:

  • We define a UserMessage model using Pydantic
  • The validate_body decorator ensures that incoming messages match our model
  • We can use either the standard callback format or simplified model-only format
  • Invalid messages will raise PikadanticValidationError

🛠️ Contributing

Contributions are welcome! If you'd like to add a new feature or fix a bug, please:

  • Set up your local environment using uv.
  • Run make install to install dependencies.
  • Ensure 100% test coverage for your changes.
  • Open a pull request and tag @karta9821 as a reviewer.
  • Pull requests without sufficient tests or that reduce test coverage will not be accepted.

⚖️ License

This project is licensed under the MIT License. See the LICENSE file for details.


Note: Pikadantic is currently in an experimental phase. Use with caution in production environments.


🙏 Acknowledgments

This project was inspired by pika-pydantic.

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

pikadantic-0.0.2.tar.gz (40.1 kB view details)

Uploaded Source

Built Distribution

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

pikadantic-0.0.2-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file pikadantic-0.0.2.tar.gz.

File metadata

  • Download URL: pikadantic-0.0.2.tar.gz
  • Upload date:
  • Size: 40.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pikadantic-0.0.2.tar.gz
Algorithm Hash digest
SHA256 9c3604bf8a3a3a8caf1f3a1ce75ebd1706c93d855befc0364a67cea347c6252b
MD5 b06f80b79b0da03dbf5b621cbd8f97e9
BLAKE2b-256 9517b25560b077d62f1b8ec87bcbd8a2c526604179391682f5b3b008de2f400f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pikadantic-0.0.2.tar.gz:

Publisher: publish.yml on karta9821/pikadantic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pikadantic-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: pikadantic-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pikadantic-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1e426bee120144c50dda5eee7fea3b695986584578bdebf17214e7d2abc26fc1
MD5 ccac56d8cbe80580c062d47edb76b99f
BLAKE2b-256 faeaad2d980631849f016b69ae527154898392a10cc029fb71c4a2bb15e40a2c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pikadantic-0.0.2-py3-none-any.whl:

Publisher: publish.yml on karta9821/pikadantic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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