Pikadantic provides robust data validation for RabbitMQ messaging
Project description
Pikadantic
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
UserMessagemodel using Pydantic - The
validate_bodydecorator 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 installto install dependencies. - Ensure 100% test coverage for your changes.
- Open a pull request and tag
@karta9821as 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
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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c3604bf8a3a3a8caf1f3a1ce75ebd1706c93d855befc0364a67cea347c6252b
|
|
| MD5 |
b06f80b79b0da03dbf5b621cbd8f97e9
|
|
| BLAKE2b-256 |
9517b25560b077d62f1b8ec87bcbd8a2c526604179391682f5b3b008de2f400f
|
Provenance
The following attestation bundles were made for pikadantic-0.0.2.tar.gz:
Publisher:
publish.yml on karta9821/pikadantic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pikadantic-0.0.2.tar.gz -
Subject digest:
9c3604bf8a3a3a8caf1f3a1ce75ebd1706c93d855befc0364a67cea347c6252b - Sigstore transparency entry: 211597228
- Sigstore integration time:
-
Permalink:
karta9821/pikadantic@061d69be212ba465d3a7937c384946eedac38d4e -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/karta9821
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@061d69be212ba465d3a7937c384946eedac38d4e -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e426bee120144c50dda5eee7fea3b695986584578bdebf17214e7d2abc26fc1
|
|
| MD5 |
ccac56d8cbe80580c062d47edb76b99f
|
|
| BLAKE2b-256 |
faeaad2d980631849f016b69ae527154898392a10cc029fb71c4a2bb15e40a2c
|
Provenance
The following attestation bundles were made for pikadantic-0.0.2-py3-none-any.whl:
Publisher:
publish.yml on karta9821/pikadantic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pikadantic-0.0.2-py3-none-any.whl -
Subject digest:
1e426bee120144c50dda5eee7fea3b695986584578bdebf17214e7d2abc26fc1 - Sigstore transparency entry: 211597235
- Sigstore integration time:
-
Permalink:
karta9821/pikadantic@061d69be212ba465d3a7937c384946eedac38d4e -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/karta9821
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@061d69be212ba465d3a7937c384946eedac38d4e -
Trigger Event:
release
-
Statement type: