Skip to main content

PolyModel, a modern, flexible ORM with full Pydantic compatibility

Project description

PolyModel

An awesomely simple Python ORM built on SQLModel's foundation, with polymorphic inheritance and active maintenance.

IMPORTANT: PolyModel is still under heavy development and IS NOT READY for production usage**

Documentation: https://docs.polymodel.dev Source Code: https://github.com/rmonvfer/polymodel

Why PolyModel?

PolyModel extends SQLModel with essential features for production applications:

  • Polymorphic inheritance - Full support for joined table inheritance patterns
  • Community-driven - Pull requests reviewed within days, not months
  • Production-tested - Currently running in production systems
  • Drop-in replacement - Fully compatible with existing SQLModel code

We deeply appreciate SQLModel's innovative approach to combining SQLAlchemy and Pydantic. PolyModel builds on this foundation while ensuring the features and maintenance that production applications require.

Installation

pip install polymodel

Migration from SQLModel

Simply change your imports:

# Before
from sqlmodel import Field, SQLModel, Session

# After
from polymodel import Field, Model, Session

All your existing code continues to work.

Key Features

PolyModel supports all the same features as SQLModel but we've added some new features on top, the most important one is comprehensive support for polymorphic inheritance.

Polymorphic Inheritance

from polymodel import Field, Model


class User(Model, table=True):
    id: int = Field(primary_key=True)
    name: str
    type: str

    __mapper_args__ = {
        "polymorphic_on": "type",
        "polymorphic_identity": "user"
    }


class Customer(User, table=True):
    __mapper_args__ = {
        "polymorphic_identity": "customer"
    }

    credit_limit: float


class Employee(User, table=True):
    __mapper_args__ = {
        "polymorphic_identity": "employee"
    }

    department: str

Standard SQLModel Features

All the SQLModel features you know and love:

  • Python type annotations
  • Pydantic validation
  • SQLAlchemy power
  • FastAPI integration
  • Editor support with autocompletion

Roadmap

I am very aware of the multiple issues regarding the maintenance of SQLModel and I've been keeping track of the most requested features (polymorphic inheritance was one of them) in order to include them in our Roadmap.

Some of them are:

  • Support for Alembic migrations
  • Full compatibility with Pydantic v2
  • Full support for Pydantic types (like date)
  • Support for Requirement Annotations
  • Support for Annotated-based column definitions
  • Proper documentation (not tutorials)

And many, many more which I will prioritize based on the sqlmodel issue tracker and pull requests.

Example

from polymodel import Field, Session, Model, create_engine

class Hero(Model, table=True):
    id: int | None = Field(default=None, primary_key=True)
    name: str
    secret_name: str
    age: int | None = None


hero = Hero(name="Deadpond", secret_name="Dive Wilson")

engine = create_engine("sqlite:///database.db")
Model.metadata.create_all(engine)

with Session(engine) as session:
    session.add(hero)
    session.commit()

Community and Support

PolyModel is independently maintained by the Python community. While used in production at some companies, it remains an independent project focused on serving the broader Python ecosystem.

We commit to:

  • Reviewing pull requests within a reasonable time-frame.
  • Monthly releases for non-critical updates
  • Immediate patches for security issues
  • Clear communication on breaking changes
  • Maintaining compatibility with SQLAlchemy and Pydantic updates

Contributing

We welcome contributions! See our Contributing Guide for details.

License

This project is licensed under the MIT license, maintaining the same license as SQLModel.

PolyModel is based on SQLModel, created by Sebastián Ramírez (tiangolo).

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

polymodel-0.0.1.tar.gz (63.7 kB view details)

Uploaded Source

Built Distribution

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

polymodel-0.0.1-py3-none-any.whl (25.8 kB view details)

Uploaded Python 3

File details

Details for the file polymodel-0.0.1.tar.gz.

File metadata

  • Download URL: polymodel-0.0.1.tar.gz
  • Upload date:
  • Size: 63.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.13

File hashes

Hashes for polymodel-0.0.1.tar.gz
Algorithm Hash digest
SHA256 ce1713847d2f76a7e6fab491b7b6eb63d13ff37b9828f325578f3bf695e7a564
MD5 df9a8aa6f00288d6a11b2fe6a4949466
BLAKE2b-256 6c8d293e581ee657d2c07a34c497508c69c4f8f2f42010f53c5b507380a91c91

See more details on using hashes here.

File details

Details for the file polymodel-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: polymodel-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 25.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.13

File hashes

Hashes for polymodel-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5d9c971d67cd51fd5b609a1f120a6b0d2f04cb12506462234b865f2258550e34
MD5 a153b5bf600913cf91538a41a5fdc869
BLAKE2b-256 153bc1b425a51898694d4afeb0e0665a34acd839b09574e69af81f3edd47f97c

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