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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

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

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for pydantic_visualizer-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 934f4f255469236bfc18bb421d043f0970f9a75399dff60b1d9ad58cf0ea89b0
MD5 9134a3b44be4747499041bd09547eabc
BLAKE2b-256 144f5ee3ac91ca3d48b4f4ebc708c078ac739512b8a275787341c8a8ea22fa7d

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