Skip to main content

in4viz - ER図可視化ライブラリ

Python製のER図専用可視化ライブラリ。SVGとdraw.io形式での出力をサポートします。

特徴

  • 2つの出力形式: SVGとdraw.io (mxGraph XML)
  • 統合されたコアアーキテクチャ: 共通のデータモデルとレイアウトエンジン
  • 自動レイアウト: FK関係を考慮した階層的配置
  • 日本語対応: 論理名・物理名の両方表示
  • カーディナリティ表示: IE記法でのカーディナリティ表現
  • 複数の線種: 直線、クランク、スプライン

インストール

pip install in4viz

基本的な使い方

SVG出力

from in4viz import ERDiagram, Table, Column, LineType, Cardinality

# SVGバックエンドでER図を作成
diagram = ERDiagram(backend='svg')

# テーブルを定義
users_table = Table(
    name='users',
    logical_name='ユーザー',
    columns=[
        Column('id', 'ID', 'INT', primary_key=True, nullable=False),
        Column('name', '名前', 'VARCHAR(100)', nullable=False),
        Column('email', 'メール', 'VARCHAR(255)', nullable=False, index=True),
    ]
)

posts_table = Table(
    name='posts',
    logical_name='投稿',
    columns=[
        Column('id', 'ID', 'INT', primary_key=True, nullable=False),
        Column('user_id', 'ユーザーID', 'INT', nullable=False, foreign_key=True),
        Column('title', 'タイトル', 'VARCHAR(200)', nullable=False),
        Column('content', '本文', 'TEXT'),
    ]
)

# テーブルを追加
diagram.add_table(users_table)
diagram.add_table(posts_table)

# FK関係を追加
diagram.add_edge(
    'posts', 'users',
    line_type=LineType.CRANK,
    cardinality=Cardinality(from_side='*', to_side='1')
)

# SVGファイルとして保存
diagram.save('er_diagram.svg')

draw.io出力

from in4viz import ERDiagram, Table, Column

# draw.ioバックエンドでER図を作成
diagram = ERDiagram(backend='drawio')

# テーブルを追加(同じTableオブジェクトを使用)
diagram.add_table(users_table)
diagram.add_table(posts_table)
diagram.add_edge('posts', 'users')

# draw.ioファイルとして保存
diagram.save('er_diagram.drawio')

バックエンド直接指定

特定のバックエンドを直接使用することもできます:

from in4viz.backends.svg import SVGERDiagram
from in4viz.backends.drawio import DrawioERDiagram

# SVG専用
svg_diagram = SVGERDiagram()
svg_diagram.add_table(users_table)
svg_diagram.save_svg('output.svg')

# draw.io専用
drawio_diagram = DrawioERDiagram()
drawio_diagram.add_table(users_table)
drawio_diagram.save_drawio('output.drawio')

アーキテクチャ

in4viz/
├── core/                  # 共通コア(80%)
│   ├── models.py         # データモデル(Table, Column, LineType, Cardinality)
│   ├── layout.py         # レイアウトアルゴリズム(階層構築、自動配置)
│   └── text_metrics.py   # 文字幅計算
├── backends/             # 出力形式別実装(20%)
│   ├── svg/             # SVG出力
│   │   ├── canvas.py
│   │   ├── stencil.py
│   │   └── renderer.py
│   └── drawio/          # draw.io出力
│       ├── canvas.py
│       ├── stencil.py
│       ├── renderer.py
│       └── generator.py
└── er_diagram.py        # ユーザーAPI

主要機能

データモデル

  • Table: テーブル定義(論理名・物理名)
  • Column: カラム定義(型、制約、PK/FK/Index)
  • LineType: 線種(STRAIGHT, CRANK, SPLINE)
  • Cardinality: カーディナリティ(1, 0..1, *, 1..*など)

レイアウトエンジン

  • FK関係を考慮した階層的自動配置
  • 逆トポロジカルソートによる階層構築
  • 関連テーブルの隣接配置
  • 動的キャンバスサイズ調整

表示機能

  • テーブル名:論理名 (物理名)
  • カラム:論理名 (物理名) 型 [制約]
  • PKカラムの境界線表示
  • NOT NULLマーカー(黒四角)
  • FK、Indexの制約表示

ライセンス

MIT License

開発

# 開発モードでインストール
cd packages/in4viz
pip install -e .

# テスト実行
pytest

貢献

プルリクエストを歓迎します!バグ報告や機能要望はIssueでお願いします。

Metadata

Release files for in4viz 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for in4viz 0.7.0
File Size Uploaded Provenance Actions
in4viz-0.7.0.tar.gz 33.7 kB Without provenance Details for in4viz-0.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for in4viz 0.7.0
File Interpreter ABI Platform Actions
in4viz-0.7.0-py3-none-any.whl Python 3 none any Details for in4viz-0.7.0-py3-none-any.whl

Total release size: 72.2 kB

Release files / in4viz-0.7.0.tar.gz

Download URL in4viz-0.7.0.tar.gz
Size 33.7 kB
Tags Source
SHA-256 checksum
How to use checksums
fbc29f66d31742ed68698793692a40b5a99f4181444397147fb25d43e9310e6c
BLAKE2b-256 checksum
How to use checksums
d362de55ba06e440d1d3080c099273b3b49b8121634c509425aa9ea78d61725c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.12.3 Linux/5.15.136-tegra

Release files / in4viz-0.7.0-py3-none-any.whl

Download URL in4viz-0.7.0-py3-none-any.whl
Size 38.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5326683b47528f801daba4f7c229b0ee37c2073b6f7eef39e024ac7f63b33ea3
BLAKE2b-256 checksum
How to use checksums
425260c2d4a40138a9200273c7c2ac7879add1c6cc0d4c4f9d29a2d7fda960e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.12.3 Linux/5.15.136-tegra

Security for in4viz 0.7.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page