jts_erd: Create an ERD from JSON-table-schemas

jts_erd creates an ERD (entity-relationship diagram).

It requires an extension of a json-table-schema as input.

Depends on pygraphviz.

Introduction

For now please look at these slides: 20150927_talk.pdf

TL;DR Generate an entyty-relationship diagram for a schema given as JSON-table-schema.

Example of a resulting ERD:

_images/example.png

Installation

Install graphviz and build tools:

aptitude install pkg-config build-essential graphviz libgraphviz-dev

You will need at least PyGraphviz 1.3.1 when using python3.

Currently (as of version 1.3.1 of pygraphviz) on at least debian and ubuntu you need special install options due to a bug (https://github.com/pygraphviz/pygraphviz/issues/71):

pip3 install pygraphviz --install-option="--include-path=/usr/include/graphviz" --install-option="--library-path=/usr/lib/graphviz/"

(gcc still throws a warning.)

Prepare a virtualenv with python3:

mkdir jts_erd
cd jts_erd
virtualenv -p python3
source bin/activate

In the virtualenv root dir:

git clone https://github.com/iburadempa/jts_erd.git

Usage examples

The main function jts_erd.get_graph() creates a graphviz graph from a (JSON-decoded) JSON-table-schema. An accompanying function, jts_erd.save_svg(), renders a graph in SVG format and saves it.

For examples look at the examples directory, https://github.com/iburadempa/jts_erd/tree/master/examples

API

jts_erd

Generate an entity-relationship diagram from an extended JSON table schema.

JSON table schema is a simple schema for describing the structure of tabular data. It can be extended to allow for a comprehensive representation of an SQL relational database schema.

Starting from such a description this python module generates visualizations of the database schema using graphviz via PyGraphviz.

jts_erd.jts_erd.get_graph(json_table_schema, **options)[source]

Create and return a graph from the given json_table_schema.

All keys from options_defaults are allowed in kwargs.

jts_erd.jts_erd.options_defaults = {'bgcolor_indexes': '#ccccff', 'default_namespace_name': 'public', 'display_columns': True, 'display_crowfoots': True, 'display_indexes': True, 'display_tooltips': True, 'edge_thickness': 1.0, 'fontname': 'Helvetica', 'fontsize': 8, 'fontsize_label': 6, 'fontsize_title': 10, 'html_color_default': '#ccff99', 'html_color_header': 'lightgrey', 'html_color_header_for_table': {}, 'html_color_highlight': '#33cc99', 'omit_isolated_tables': False, 'rankdir': 'LR', 'table_comment_wrap_width': 70}

Options and their default values.

Options:

  • html_color_header

  • html_color_header_for_table

  • html_color_default

  • html_color_highlight

  • fontname

  • fontsize

  • fontsize_title

  • fontsize_label

  • bgcolor_indexes

  • rankdir: ‘LR’ or ‘RL’; whether dependent tables appear on the right (left) hand side

  • edge_thickness

  • display_columns: bool

  • display_indexes: bool

  • display_crowfoots: bool

  • display_tooltips: bool

  • omit_isolated_tables: bool

  • default_namespace_name: string

jts_erd.jts_erd.save_svg(json_database_schema, filepath, **options)[source]

Write an ERD in SVG format for a database to a file.

json_database_schema must be compatible with what pg_jts produces. filepath must end in ‘.svg’.

Source: https://github.com/iburadempa/jts_erd/