19

The question is not the same as What’s the best way to generate a UML diagram from Python source code?, but the other way around.

Topcoder UML tool automatically generates code in only Java or C#. Since I need to create a very depended data structure at a point, I am hesitant to turn to Java. I want to use Python. So:

  1. Is there an UML-like tool that automatically generates Python code from your diagram?

  2. If there is, is it possible to generate it from the Topcoder UML tool?

  3. Can you shortly compare the tools?

Community
  • 1
  • 1
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697

7 Answers7

15

Enterprise Architect is able to generate python code code from UML diagrams.
It is also able to also perform some reverse engineering, and therefore maintain the two versions (UML and python) synchronized together.

However, I have never used it in that way, except for some small tests just to see it in action. I personally find productivity in Python so high, that even if I am really satisfied with EA, I prefer it just to document the design.

rob
  • 36,896
  • 2
  • 55
  • 65
  • +1: I use UML for conceptual sketches. The real code is so easy to write that big, formal, detailed UML isn't helpful. – S.Lott Jul 28 '09 at 16:07
  • EA only works for windows. sorry for it. I would want to try it on my mac. – NullPointer Jan 06 '10 at 15:07
  • 1
    @S.Lott, detailed UML isn't helpful unless the project is very large... then detailed UML saves your skin many times over – Mike Pennington Jun 25 '11 at 03:31
  • @Mike Pennington: Detailed UML is isomorphic to code. It's easier to write the code. – S.Lott Jun 27 '11 at 10:09
  • 2
    @S.Lott, maps are isomorphic to city topology; amazingly, people continue to buy maps. – Mike Pennington Jun 27 '11 at 23:57
  • @Mike Pennington: True. But a really bad analogy. GPS maps lack a great many details. For instance, you can't actually into any building. But detailed UML actually is executable by an interpreter, making it isomorphic to code, and much, much more difficult to create. – S.Lott Jun 27 '11 at 23:59
  • @S.Lott, I edited out GPS upon reflection before I saw your comment; nevertheless, the point is you can write sufficiently-complex class relationships that detailed UML is very useful... likewise in some cities, normal people wouldn't dream of navigating to random locations from memory. I agree that UML code-generation / round-tripping is often more complicated than building the relationships by hand – Mike Pennington Jun 28 '11 at 00:03
  • @Mike Pennington: That is my point. There's a limit to the value of UML, and code-level detail is past the point of value. – S.Lott Jun 28 '11 at 00:11
  • @S.Lott, what exactly are you calling "code-level detail"? This is where we may not agree. – Mike Pennington Jun 28 '11 at 00:12
  • @Mike Pennington: Detailed UML is isomorphic to code. I think that's what I said. – S.Lott Jun 28 '11 at 02:54
  • @S.Lott, code is not always easier to read than UML. That's what I said – Mike Pennington Jun 28 '11 at 03:24
  • @Mike Pennington: I have no idea what you're talking about. The "big picture" or overview or summary or high-level design is hard to grasp from code. The code-level details are hard to depict in UML. They're different things. Details UML -- at the code level -- is obscure and complex. UML overviews, however, can act as a visual road map into the code. For details -- and only details -- UML is obscure and code is clear. For overviews -- and only overviews -- UML can help. A blanket statement about "UML" being easier to read makes very little sense. Why do you keep saying it? – S.Lott Jun 28 '11 at 09:52
  • @S.Lott because you continue to rant and be ambiguous about what *specifically* you mean about detailed UML being hard to read. For the record, I consider detailed UML to include anything in (for Class diagrams) Chapter 3 of Martin Fowler's book... and sometimes parts of Chapter 5. UML Sequence diagrams, and Use cases are rather useful... are we disagreeing? If not, that's why I asked you several comments ago what you meant by "code-level detail" – Mike Pennington Jun 28 '11 at 11:05
  • @Mike Pennington: What words should I use to clarify my point? Detailed UML is isomorphic to code. What more could I possibly say? Please provide some guidance. – S.Lott Jun 28 '11 at 11:08
  • 1
    The advantage of UML over code is that a single or few architects can specify ins, outs, and functionality in a rough form from UML. As th team of developers grows in numbers, UML scaffold generation becomes more beneficial. – RobotHumans Dec 30 '11 at 02:56
  • @NullPointer Just FYI, EA is one of the explicitly support packages for CrossOver (the commercial version of Wine). I use EA on Windows, OSX, and Ubuntu with very few problems. – kdopen Jan 05 '15 at 23:51
7
  • PyUML - a Python Roundtrip Tool for Eclipse
  • PyIdea: PyNSource UML & Patterns IDE for Python
Brandon E Taylor
  • 24,881
  • 6
  • 47
  • 71
5

You can use DIA, and then install dia2code, it will generate from UML to code in python. I use it in PHP5 and Java.

$ sudo apt-get install dia dia2code
metamorph
  • 241
  • 3
  • 8
3

The Umbrello UML modeller for KDE support Python as an export language.

Mark
  • 28,783
  • 8
  • 63
  • 92
0

Some tools:

ThibThib
  • 8,010
  • 3
  • 30
  • 37
  • 2
    Does gaphor do Python reverse engineering? Or is it a UML diagramming tool written in Python/GTK+? – S.Lott Jul 27 '09 at 22:26
0

Search with Ubuntu found:

$ apt-cache search python uml
boa-constructor - RAD tool for Python and WxWindows application
dia2code - a dia-UML code generator
spe - Stani's Python Editor

Quick testing revealed that DIA is the only program, where you can export your UML diagram to Python. I am very suspicious about the quality of DIA because it is less intuitive to use than the Topcoder UML program. Perhaps, the other programs, suggested by other repliers, are better.

Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
0

Try this link-

https://www.visual-paradigm.com/support/documents/vpuserguide/276/330/7400_instantgener.html

Select Tools > Code > Instant Generator from the toolbar. In the Instant Generator window, select Python as the Language. Fill in the Output Path, which is the directory where you want the code to generate to. Select the classes to generate code. In the Diagrams tab, you can select the diagrams to generate code for classes in the selected diagrams. Alternatively, open the Model Elements tab and select the classes to generate code.

Mohammad Shahid Siddiqui
  • 3,730
  • 2
  • 27
  • 12