A flexible, type-safe relationship management system for Python models built on top of Pydantic [source|PyPI]. Provides ORM-style relationships with caching support and strict type checking through Pydantic's validation system.
- Built on Pydantic for robust data validation and serialization
- Type-safe relationship declarations with full type hints support
- Configurable caching with TTL support
- Support for common relationship types (BelongsTo, HasOne, HasMany)
- Flexible query and loading interfaces
- Automatic relationship validation
- Forward reference support for circular dependencies
- Python >= 3.8
- pydantic >= 2.0
- pytest >= 7.0 (for testing)
- coverage >= 7.0 (for test coverage)
from typing import ClassVar
from pydantic import BaseModel
from relations import RelationManagementMixin, HasMany, BelongsTo
class Department(RelationManagementMixin, BaseModel):
id: int
name: str
employees: ClassVar[HasMany["Employee"]] = HasMany(
foreign_key="department_id",
inverse_of="department"
)
class Employee(RelationManagementMixin, BaseModel):
id: int
name: str
department_id: int
department: ClassVar[BelongsTo["Department"]] = BelongsTo(
foreign_key="department_id",
inverse_of="employees"
)Detailed documentation is available in the following sections: