Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I draw diagrams from database in python

How can I visually model items in a database using python?

I have a Django project that currently models my home network in the admin views. It currently describes what devices there are and what they are connected to. For example:

Devices:
    Computer1
    Computer2
    Laptop1
    Mobile1
    Router1
    ROuter2

ConnectionTypes:
    Wireless24ghz
    Wireless5ghz
    cat5
    cat5e
    cat6

Connections:
    host1:
        src:Computer1
        dst:Router1
        con_type:cat5e
    trunk1:
        src:Router1
        dst:Router2
        con_type:cat6
    host2:
        src:Mobile1
        dst:Router1
        con_type:Wireless24ghz

The database is a bit more complex than this, however I'm keeping it simple for now as it's not that important.

What I am wondering is, how I can graphically model my network using python code to look at the database tables? By graphically model I mean something similar to a Visio diagram in that I can see it and (not necessary but a HUGE bonus) interact with it, either via webpage or application.

Are there any existing python libraries that provide this sort of functionality? I understand JavaScript is good for this kind of modelling but I'm completely unsure of how I would go about doing it.

It's worth noting I'm not after anything fancy, simply drawing devices as rectangles and connections as lines going between rectangles is good enough.

like image 237
JamoBox Avatar asked Oct 23 '15 20:10

JamoBox


People also ask

Can we draw diagrams in Python?

With the Python script written, you can run it to create the diagram. Start by installing the requirements with Pip: pip3 install -r requirements.

How do you create a database diagram?

To create a new database diagramIn Object Explorer, right-click the Database Diagrams folder or any diagram in that folder. Choose New Database Diagram on the shortcut menu. The Add Table dialog box appears. Select the required tables in the Tables list and click Add.


1 Answers

I am pretty sure there is no ready solution for this. Look at the graphviz library and make a management command to create a DOT graph. Here is a graphviz tutorial article http://matthiaseisen.com/articles/graphviz/

like image 104
Mad Wombat Avatar answered Sep 21 '22 14:09

Mad Wombat