Skip to content

vistart/relations

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Relations Package

简体中文

GitHub License GitHub Downloads (all assets, all releases)

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.

Features

  • 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

Requirements

  • Python >= 3.8
  • pydantic >= 2.0

Development Requirements

  • pytest >= 7.0 (for testing)
  • coverage >= 7.0 (for test coverage)

Quick Start

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"
    )

Documentation

Detailed documentation is available in the following sections:

License

MIT License

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages