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.3.0.tar.gz (25.7 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.3.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pydantic_visualizer-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b976897e826637a812ccf03306a458a0bb2cddae4057ae3b9458751102477884
MD5 76987bf6a4a875d31a9edfc55dfa743c
BLAKE2b-256 3317c738f40a814f5ec203740f957e9c0c6e81c42945c3a1c6af8fe9c820e9b6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pydantic_visualizer-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e7834428d2bc503d087d01aed4d2c7f3fec571074562583399a7cd6cdba92f4d
MD5 ce1b5a84ea7517004566919a64aa4e1a
BLAKE2b-256 fd387306202c4f7f4f202fc2676808b0dc9f141124eee8c40d0d2555d3839583

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