Skip to main content

A Python library for managing model relationships

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_relations-0.1.0.post1.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_relations-0.1.0.post1-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file python_relations-0.1.0.post1.tar.gz.

File metadata

  • Download URL: python_relations-0.1.0.post1.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for python_relations-0.1.0.post1.tar.gz
Algorithm Hash digest
SHA256 7bc1c880d459f1c3591bd7e069697d7b297c6e4faf30403fd0070048cf300bbb
MD5 a3904d869a7c539295918bfd18daee89
BLAKE2b-256 fb6b4c00c00627d08e5a70dd199ba817bf88cd9f2206282c4c4e20395384506a

See more details on using hashes here.

File details

Details for the file python_relations-0.1.0.post1-py3-none-any.whl.

File metadata

File hashes

Hashes for python_relations-0.1.0.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 6aee741378e6dc0a4dfa15e32e3b1a0e48ed0e895dec76fafc7444bbb35d125e
MD5 d5457d188aeddd55229cac554f8b8732
BLAKE2b-256 f872e310f1bb9dc2bac59fd2f983ac117776e433668cd608ad6c5f001998a0e8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page