Skip to main content

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.

Metadata

Release files for pikadantic 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pikadantic 0.0.2
File Size Uploaded Provenance Actions
pikadantic-0.0.2.tar.gz 40.1 kB With provenance Details for pikadantic-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pikadantic 0.0.2
File Interpreter ABI Platform Actions
pikadantic-0.0.2-py3-none-any.whl Python 3 none any Details for pikadantic-0.0.2-py3-none-any.whl

Total release size: 46.4 kB

Release files / pikadantic-0.0.2.tar.gz

Download URL pikadantic-0.0.2.tar.gz
Size 40.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9c3604bf8a3a3a8caf1f3a1ce75ebd1706c93d855befc0364a67cea347c6252b
BLAKE2b-256 checksum
How to use checksums
9517b25560b077d62f1b8ec87bcbd8a2c526604179391682f5b3b008de2f400f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 12, 2025.

Transparency log

Release files / pikadantic-0.0.2-py3-none-any.whl

Download URL pikadantic-0.0.2-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e426bee120144c50dda5eee7fea3b695986584578bdebf17214e7d2abc26fc1
BLAKE2b-256 checksum
How to use checksums
faeaad2d980631849f016b69ae527154898392a10cc029fb71c4a2bb15e40a2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 12, 2025.

Transparency log

Security for pikadantic 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pikadantic-0.0.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 12, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page