Generate PlantUML ERD diagrams from SQLModel, SQLAlchemy, Django, Pydantic and dataclass models
Project description
๐๏ธ erdify
๐ Generate beautiful PlantUML Entity Relationship Diagrams from your SQLModel, SQLAlchemy, Django, Pydantic and dataclass models automatically!
erdify parses your model files using AST (Abstract Syntax Tree) and generates comprehensive ERD diagrams in PlantUML format. It supports SQLModel, SQLAlchemy 2.0, Django ORM, Pydantic and standard-library dataclasses. No database connection required!
โจ Features
- ๐ Automatic ERD Generation - Parse your models and generate PlantUML diagrams
- ๐งฌ 5 Frameworks - SQLModel, SQLAlchemy 2.0, Django ORM, Pydantic and dataclasses
- ๐ AST-Based Parsing - No imports needed, works with any valid Python code
- ๐ฏ Zero Runtime Dependencies - Uses only Python standard library
- ๐ Relationship Detection - Automatically detects foreign keys and relationships
- ๐ Key Inference -
--infer-keysderives PK/FK from field names for keyless models - ๐ซ Exclude Patterns - Filter out entities by class or table name with glob patterns
- ๐๏ธ Source Filtering - Restrict the diagram to specific model kinds with
--sources - โ๏ธ Config File - Commit options under
[tool.erdify]inpyproject.toml - โ
Drift Check -
--checkfails CI/pre-commit when the committed diagram is stale - ๐ฆ Inheritance Support - Resolves fields from base classes and mixins
- ๐ท๏ธ Enum Support - Includes enum definitions in the diagram
- ๐ Link Table Detection - Identifies many-to-many association tables structurally
- ๐ง 4 Output Formats -
--formatemits PlantUML, Mermaid (renders natively on GitHub), JSON, or a self-contained HTML preview - ๐จ Beautiful Output - Clean, readable diagrams with proper styling
๐ Quick Start
# Run without installing (or `pip install erdify`)
uvx erdify ./src/database -o erd.puml
# Output to stdout, with a custom title
erdify ./src/models --title "My Database Schema"
See the documentation for installation options, the full CLI, the Python API and more.
๐งฌ One Schema, Five Frameworks
The snippets below all describe the same User / Order schema โ only the
syntax differs. Each one produces the identical diagram:
โน๏ธ The SQLModel, SQLAlchemy and Django versions declare keys explicitly (Django via its implicit
idandForeignKey). Pydantic and dataclasses have no key concept, so they are rendered with--infer-keys(idโ PK,<x>_idโ FK) to match. The runnable sources live indocs/examples/.
| SQLModel | SQLAlchemy 2.0 |
|---|---|
from sqlmodel import (
Field, Relationship, SQLModel,
)
class User(SQLModel, table=True):
__tablename__: str = "user"
id: int = Field(primary_key=True)
name: str
email: str
orders: list["Order"] = Relationship(
back_populates="user")
class Order(SQLModel, table=True):
__tablename__: str = "order"
id: int = Field(primary_key=True)
user_id: int = Field(
foreign_key="user.id")
total: float
user: "User" = Relationship(
back_populates="orders")
|
from sqlalchemy import ForeignKey
from sqlalchemy.orm import (
DeclarativeBase, Mapped,
mapped_column, relationship,
)
class Base(DeclarativeBase): ...
class User(Base):
__tablename__ = "user"
id: Mapped[int] = mapped_column(
primary_key=True)
name: Mapped[str] = mapped_column()
email: Mapped[str] = mapped_column()
orders: Mapped[list["Order"]] = (
relationship(back_populates="user"))
class Order(Base):
__tablename__ = "order"
id: Mapped[int] = mapped_column(
primary_key=True)
user_id: Mapped[int] = mapped_column(
ForeignKey("user.id"))
total: Mapped[float] = mapped_column()
user: Mapped["User"] = relationship(
back_populates="orders")
|
Pydantic --infer-keys | Dataclass --infer-keys |
from pydantic import BaseModel
class User(BaseModel):
id: int
name: str
email: str
orders: list["Order"] = []
class Order(BaseModel):
id: int
user_id: int
total: float
user: "User"
|
from dataclasses import dataclass, field
@dataclass
class User:
id: int
name: str
email: str
orders: list["Order"] = field(
default_factory=list)
@dataclass
class Order:
id: int
user_id: int
total: float
user: "User" = None
|
| Django ORM | |
from django.db import models
class User(models.Model): # implicit `id` PK; CharField/EmailField -> str
name = models.CharField(max_length=100)
email = models.EmailField()
class Meta:
db_table = "user"
class Order(models.Model):
user = models.ForeignKey( # -> user_id : int foreign key column
User, on_delete=models.CASCADE)
total = models.FloatField() # -> float
class Meta:
db_table = "order"
| |
How each framework is detected & parsed:
| Framework | Detected by | Keys | Relationships |
|---|---|---|---|
| SQLModel | table=True |
Field(primary_key=โฆ, foreign_key=โฆ) |
Relationship() |
| SQLAlchemy 2.0 | __tablename__ + Mapped[...] columns |
mapped_column(primary_key=โฆ), ForeignKey(...) |
relationship() (lowercase) |
| Django ORM | models.Model subclass |
primary_key=True or implicit id, ForeignKey/OneToOneField |
ForeignKey (N:1), OneToOneField (1:1), ManyToManyField (M:N, incl. through=) |
| Pydantic | BaseModel subclass (incl. transitive) |
--infer-keys only |
nested model refs (user: User, list["Order"]) |
| Dataclass | @dataclass decorator |
--infer-keys only |
nested model refs |
โน๏ธ Mixins / abstract bases (e.g. a SQLAlchemy mixin without
__tablename__, or a Djangoclass Meta: abstract = Truebase) are not drawn as tables, but their columns are inherited into concrete entities.
For a worked example with the generated PlantUML, see the Frameworks Overview; for Django specifics see Django ORM.
๐ Documentation
- Installation โ pip, uv, pipx, or run with uvx
- CLI & Python API โ all CLI options, running as a module, and the Python API
- Output Formats โ PlantUML & Mermaid,
--format, output naming - Filtering & Key Inference โ
--exclude,--exclude-paths,--sources,--infer-keys - Viewing the Diagram โ render online, locally with PlantUML, or in VS Code
- CI/CD & pre-commit โ automate ERD generation in CI and on commit
- Frameworks Overview โ a worked example with the generated PlantUML output
- Django ORM โ Django-specific parsing details
๐ Supported Features
| Feature | Status | Notes |
|---|---|---|
| Primary Keys | โ | Field(primary_key=True) |
| Foreign Keys | โ | Field(foreign_key="table.column") |
| Nullable Fields | โ | str | None or Optional[str] |
| Default Values | โ | Field(default=value) |
| Indexes | โ | Field(index=True) |
| Enums | โ | Python Enum classes |
| Relationships | โ | Relationship() |
| Inheritance | โ | Mixin classes supported |
| Link Tables | โ | Many-to-many detection |
| Custom Table Names | โ | __tablename__ attribute |
| Exclude Patterns | โ | --exclude glob on class/table name |
| Key Inference | โ | --infer-keys for Pydantic/dataclass (id, <x>_id) |
| SQLModel | โ | Field() / Relationship() |
| SQLAlchemy 2.0 | โ | Mapped[...] / mapped_column() |
| Pydantic | โ | BaseModel subclasses, nested refs as relationships |
| Dataclass | โ | @dataclass, nested refs as relationships |
๐ฌ Community
Questions, ideas, or want to show off an ERD erdify generated? Join the Discussions. For open-ended topics and feature direction, Discussions are the place; concrete bugs and proposals go to Issues.
๐ค Contributing
Contributions are welcome! Have a bug or a concrete feature request? Please open an issue, and see CONTRIBUTING.md for guidelines. Shipped changes are tracked in the changelog.
๐ Security
For security concerns, please see SECURITY.md.
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
erdify stands on the shoulders of great open-source projects:
Supported model frameworks
- SQLModel - The awesome SQL database library
- SQLAlchemy - The Python SQL toolkit and ORM
- Django - The web framework whose ORM models erdify parses
- Pydantic - Data validation using Python type hints
- dataclasses - Python standard-library data classes
Rendering & output
Tooling & infrastructure
- uv - Packaging, builds and dependency management
- Ruff - Linting and formatting
- mypy - Static type checking
- pytest - Testing framework
- pre-commit - Git hook management
Community
- Contributor Covenant - Our Code of Conduct
- Keep a Changelog - Changelog format
- And everyone who contributes issues, ideas and pull requests ๐
Made with โค๏ธ by Devsuit GmbH
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file erdify-0.7.0.tar.gz.
File metadata
- Download URL: erdify-0.7.0.tar.gz
- Upload date:
- Size: 24.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e771aa63aeaf74f2e7015f7f0bf52f03556acf3339313125feaa4587e55f4e16
|
|
| MD5 |
f09297caa0a8c0fc9d99087208331160
|
|
| BLAKE2b-256 |
ae395a22b81bb77a1c914f655f8bd3e90da10084799eb09a080fd3c9a02af510
|
File details
Details for the file erdify-0.7.0-py3-none-any.whl.
File metadata
- Download URL: erdify-0.7.0-py3-none-any.whl
- Upload date:
- Size: 27.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0acc8d9194cee2ce2fcb41e1b7ff4d58663e6487902b52b4923aee7adf150890
|
|
| MD5 |
19c71564097f0fbc2d55363f29c6410d
|
|
| BLAKE2b-256 |
720bf598b399c834429eb8bbc74e87826bc7f3b986b7d5ad68a85605dfdee0f9
|