Pico-Pydantic¶
Declarative, AOP-based Pydantic validation for pico-ioc managed components.
Features¶
@validateDecorator: Mark methods for automatic argument validation- AOP Interceptor: Validation runs before method execution via
ValidationInterceptor - Type Support:
BaseModel,List[BaseModel],Optional[BaseModel],Uniontypes - Argument Transformation: Dicts are automatically converted to BaseModel instances
- Async & Sync: Works with both
async defand regular methods
Quick Start¶
from pydantic import BaseModel, Field
from pico_ioc import component
from pico_pydantic import validate
class ItemData(BaseModel):
name: str
price: float = Field(gt=0)
@component
class InventoryService:
@validate
async def add_item(self, data: ItemData) -> dict:
# 'data' is guaranteed to be a valid ItemData instance
return data.model_dump()
Important: Validation only runs when the component is resolved from the pico-ioc container. If you instantiate the class directly (
InventoryService()),@validatehas no effect. See Getting Started for details.
Installation¶
Requirements¶
- Python 3.11+
- pico-ioc >= 2.2.0
- Pydantic 2.0+
Documentation¶
- Getting Started - Installation and basic usage
- Architecture - Design and implementation details
- FAQ - Frequently asked questions
License¶
MIT License - see LICENSE file for details.