Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to generate a UML diagram from Python source code? [closed]

A colleague is looking to generate UML class diagrams from heaps of Python source code. He's primarily interested in the inheritance relationships, and mildly interested in compositional relationships, and doesn't care much about class attributes that are just Python primitives.

The source code is pretty straightforward and not tremendously evil--it doesn't do any fancy metaclass magic, for example. (It's mostly from the days of Python 1.5.2, with some sprinklings of "modern" 2.3ish stuff.)

What's the best existing solution to recommend?

like image 380
Mike Pirnat Avatar asked Nov 03 '08 22:11

Mike Pirnat


People also ask

Can you generate UML from code?

Umbrello is a free software tool that supports a code import feature that automatically generates UML Class diagrams from your imported code. Umbrello supports up to 20 languages between C, C++, Python, Javascript and Java.

Which UML diagram is most important to start the coding of any software?

Use Case Diagram It's a great starting point for any project discussion because you can easily identify the main actors involved and the main processes of the system. You can create use case diagrams using our tool and/or get started instantly using our use case templates.


2 Answers

You may have heard of Pylint that helps statically checking Python code. Few people know that it comes with a tool named Pyreverse that draws UML diagrams from the Python code it reads. Pyreverse uses Graphviz as a backend.

It is used like this:

pyreverse -o png -p yourpackage . 

where the . can also be a single file.

like image 106
Nicolas Chauvat Avatar answered Sep 28 '22 05:09

Nicolas Chauvat


Epydoc is a tool to generate API documentation from Python source code. It also generates UML class diagrams, using Graphviz in fancy ways. Here is an example of diagram generated from the source code of Epydoc itself.

Because Epydoc performs both object introspection and source parsing it can gather more informations respect to static code analysers such as Doxygen: it can inspect a fair amount of dynamically generated classes and functions, but can also use comments or unassigned strings as a documentation source, e.g. for variables and class public attributes.

like image 27
piro Avatar answered Sep 28 '22 06:09

piro