Skip to main content

Convert Pydantic models to Mermaid class diagrams for easy visualization

Project description

Pydantic Visualizer

PyPI version Python 3.10+ License: MIT

Convert your Pydantic models into beautiful Mermaid class diagrams with ease! 🎨

Pydantic Visualizer automatically generates visual representations of your Pydantic data models, making it easier to understand complex data structures, document your APIs, and communicate your data architecture.

✨ Features

  • 🔄 Automatic Conversion: Transform Pydantic models to Mermaid diagrams instantly
  • 🎯 Relationship Detection: Automatically identifies and visualizes model relationships
  • 📊 Enum Support: Special handling and visualization for Enum types
  • 🎨 Customizable Colors: Configure colors for different element types
  • 📝 Multiple Export Formats: Save as Markdown or HTML
  • 🌐 Browser Preview: Open diagrams directly in your browser
  • 🔗 Nested Models: Handles complex nested model structures
  • Type-Safe: Fully typed with comprehensive type hints

📦 Installation

Using pip

pip install pydantic-visualizer

Using uv (recommended)

uv pip install pydantic-visualizer
uv add pydantic-visualizer

For Development

# Clone the repository
git clone https://github.com/maxime-gillot/pydantic-visualizer.git
cd pydantic-visualizer

# Install with development dependencies using uv
uv pip install -e ".[dev]"

🚀 Turn this in mermaid diagram

# Define models
class Priority(str, Enum):
    """Task priority levels."""
    LOW = "low"
    MEDIUM = "medium"
    HIGH = "high"
    URGENT = "urgent"


class Comment(BaseModel):
    """Comment on a task."""
    author: str = Field(description="Comment author")
    text: str = Field(description="Comment text")
    timestamp: str = Field(description="When the comment was made")


class Task(BaseModel):
    """Task model with priority and comments."""
    title: str = Field(description="Task title")
    description: str = Field(description="Detailed task description")
    priority: Priority = Field(description="Task priority level")
    completed: bool = Field(default=False, description="Whether task is completed")
    comments: List[Comment] = Field(default_factory=list, description="Task comments")

Task Diagram

classDiagram
class Comment {
    author   : str
    text     : str
    timestamp: str
}
style Comment fill: #FFEFDD, stroke: #000, stroke-width: 1px, color: #000
class Task {
    title      : str
    description: str
    priority   : Enum.Priority
    completed  : bool
    comments   : List[Comment]
}
style Task fill: #DDEDFF, stroke: #000, stroke-width: 1px, color: #000
Task --* Comment : Has_list_of_Comment

Save it as an html file

See the Related html file.


📚 More Examples: Visit the examples folder for 8+ complete, runnable examples covering:

  • Basic usage and nested models
  • Enum handling and custom colors
  • Complex relationships and self-referencing models
  • Saving to Markdown/HTML and browser preview
  • Adding multiple models to one diagram

See the Examples README for detailed descriptions and usage instructions.

🎨 Diagram Features

Relationship Types

  • Solid arrows (-->) for required relationships
  • Dashed arrows (..>) for optional relationships
  • Star notation (*) for list/collection relationships

Visual Indicators

  • Different colors for objects, lists, and enums
  • Dashed borders for optional nested models
  • Aligned field names for better readability

Development Setup

# Clone the repository
git clone https://github.com/Maxlo24/pydantic-visualizer.git
cd pydantic-visualizer

# Install dependencies with uv
uv pip install -e ".[dev]"

# Run tests
pytest

# Run linting
ruff check .

# Run type checking
mypy pydantic_visualizer

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • Built with Pydantic - Data validation using Python type hints
  • Diagrams rendered with Mermaid - Generation of diagrams from text

📮 Contact & Support

🗺️ Roadmap

  • Support for Pydantic v1 models
  • CLI tool for quick visualization
  • Integration with FastAPI for automatic API documentation
  • Export to additional formats (PNG, SVG, PDF)

Made with ❤️ by Maxime Gillot

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

pydantic_visualizer-0.2.0.tar.gz (23.6 kB view details)

Uploaded Source

Built Distribution

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

pydantic_visualizer-0.2.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_visualizer-0.2.0.tar.gz.

File metadata

  • Download URL: pydantic_visualizer-0.2.0.tar.gz
  • Upload date:
  • Size: 23.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.22

File hashes

Hashes for pydantic_visualizer-0.2.0.tar.gz
Algorithm Hash digest
SHA256 857e76fca13aadea02d94c8c72f7deaabb9d39008e2d1d3dd7e1521665e48fe7
MD5 8fcedb94ef40cc2ed5acddfbf0de18b5
BLAKE2b-256 df23751240364b06865160b8db0ebe36fc7ec2d8cd107c76cabf5656f987212b

See more details on using hashes here.

File details

Details for the file pydantic_visualizer-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_visualizer-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 be625d7e8a0297ab570b7639d11852e47d7baf85c87928fbbd5c20dde44ec641
MD5 a42d3da420161a6179336bcf0caa3543
BLAKE2b-256 ee8580b87be0dccae47e896731a389603dd4f423d36708c834ec83c8c29c0b33

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