pydantic-diagram
Generate ERD-style diagrams from your Pydantic models using D2.
Takes a set of Pydantic models and outputs D2 code that renders as a nice visual diagram showing model relationships, inheritance, and field types.
Installation
pip install pydantic-diagram
Usage
As a library
from pydantic import BaseModel
from pydantic_diagram import render_d2
class User(BaseModel):
id: int
name: str
class Post(BaseModel):
id: int
title: str
author: User
# Generate D2 code
# Options allow you to toggle specific features
d2_code = render_d2(
[User, Post],
show_inheritance=True,
show_composition=True
)
print(d2_code)
From the command line
# From a file path (no install needed)
pydantic-diagram path/to/models.py:User,Post
# From an installed module
pydantic-diagram myapp.models:User,Post
# Diagram all models in a module/file
pydantic-diagram myapp.models
# Write to file, then render with D2
pydantic-diagram models.py -o schema.d2
d2 schema.d2 schema.svg
CLI options
pydantic-diagram <module:models> [options]
Options:
-o, --output FILE Write to file instead of stdout
--direction DIR Layout direction: right, down, left, up (default: right)
--no-inherited Exclude inherited fields from subclasses
--no-inheritance-edges Do not draw inheritance (extends) arrows
--no-composition-edges Do not draw composition/relation arrows
--qualified-names Use fully qualified names (module.ClassName)
--no-docstrings Exclude docstrings and field descriptions
What it diagrams
- Model relationships: composition, collections, unions
- Inheritance: shows parent/child class relationships
- Field types: rendered as D2 sql_table shapes
- Self-references: handles recursive models correctly
- Docstrings: model and field descriptions appear as tooltips/constraints
Requirements
- Python 3.10+
- Pydantic 2.0+
- D2 (for rendering the output)
License
MIT
Metadata
Release files for pydantic-diagram 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pydantic_diagram-0.1.5.tar.gz | 47.1 kB | Without provenance | Details for pydantic_diagram-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pydantic_diagram-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for pydantic_diagram-0.1.5-py3-none-any.whl |
Total release size: 60.9 kB
Release files / pydantic_diagram-0.1.5.tar.gz
| Download URL | pydantic_diagram-0.1.5.tar.gz |
|---|---|
| Size | 47.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d978540cbad1da2d7faf30d28c1aa26455439a22ca6ed1d1f217151a1ff22c04
|
|
BLAKE2b-256 checksum How to use checksums |
fb6129088fcdeb6fa175076915efd39d43333dcf1e8f6ed5bf00ae29084dac68
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.11
|
Release files / pydantic_diagram-0.1.5-py3-none-any.whl
| Download URL | pydantic_diagram-0.1.5-py3-none-any.whl |
|---|---|
| Size | 13.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dea4e77103b44e7967d20e0a64266c87f9403273b3d3c8ac14ab1f5b046d9767
|
|
BLAKE2b-256 checksum How to use checksums |
373552b3555671dfbd5cff07d23f715d6da31c93f302ae9c83d6f7d529013afd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.11
|
Security for pydantic-diagram 0.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.