A reverse engineering tool for Python source code

Reverse engineer python source code into UML.

Latest Version 1.60
(c) Andy Bulka 2004-2012
License: GPL 3



  • Generates UML diagrams (see screenshot above)
  • Layout algorithm
  • Toggle between normal and ascii UML view
  • Recognises inheritance, composition and cardinality
  • Colour sibling subclasses to understand the relationships in your uml diagram.
  • Print and Print preview
  • Persistence
  • Now uses standard ast python parsing
  • Windows 7, Mac os x, Linux compatibility
  • Open Source

Proper "Python Friendly" source parsing for Python Software Developers: Unlike most off the shelf uml python code importers, pyNsource attempts to recognise tricky composition relationships that are typical in python software development. The expression


is correctly recognised as a UML attribute "somevar". pyNsource attempts to guess the cardinality of associations - if you use arrays or use


then "one to many" is assumed. More advocacy here.

Layout: Use the built in layout algorithm to help you get started in arranging your classes on the workspace. The layout algorithm uses "spring layout" and animates during layout. Overlap removal means your nodes won't overlap (unless you drag them with the SHIFT key held down). A multipass (slower) 'Optimal' Layout is also available which tries to find the best possible layout, within the constraints of not being able to 'bend' lines.

Ascii view: Hit "v" to toggle between normal UML and Ascii UML view. Ascii UML lets you copy and paste ascii uml text into your source code and text based documentation.  Optionally use something like the Java Ascii Versatile Editor to wire up your ascii uml classes nicely before pasting into your source code or documentation. See an example of ascii UML at the bottom of this readme.

pynsource command line

  • Command line tool
  • Generates java and delphi skeleton code from python source code
  • Uses an older (non ast based) python parser

The main purpose of this tool is to provide a command line tool which can generate java and delphi skeleton code from python source code, for the purpose of importing (e.g. Java source code) into other UML tools - which might have better layout and other features.

Whilst it currently uses the older python parser, it does have the feature (which my current ast based one used in pyNsourceGui.py doesn't) of optionally treat modules as classes, creating a "pseudo class" for each module/file. In such a case, module variables and functions are treated as attributes and methods of a 'class'. I hope to add the "treat modules as 'classes'" feature to the new ast based parser as used by pyNsourceGui.py in the future, as I think it allows us to visualise modules, not just classes.


  • Gui tool which parses python source code and uses the Yuml online service to generate png images of uml
  • Uses an older (non ast based) python parser

This was mainly a fun experiment but seems to work ok. The pynsource.py command
line tool can also generate Yuml text from python source code (use the -y option).


What does pynsource mean?

Since it was built in Australia, which is famous for its meat pies and sauce
at football matches, Pie-and-Sauce. Where Py = Python and Source = source code.


Windows 7, Mac and Linux versions from here

Git repository for pynsource is


Mailing List

Join the mailing list and be notified when there are new releases of PyNSource.  Send an email to pynsource-subscribe@yahoogroups.com or visit here.

Send all comments to Andy Bulka.


Posted by Marco Renedo on
Hi Andy,

I recently installed your windows executable in a Windows XP machine, I tried to graph simple python code and I got problems with the exponentiation operator. Is that expected?

Thanks in advance. 

 Answer: yes that issue has been fixed.  Thanks for the report.
Hi Andy,

Is there a way to create a png or another format from PyNSource? pyYumlGui failed to do this for me, and printing to ps did not work for me either when using lpr.

Answer: Sorry, no.  I suggest taking a screenshot.

I am new to pynsource and I am quite impressed of how well it works.

I would like only to find out if the next 2 tasks can also be implemented:
1. for the methods in the java generated file to have the variables included
2. keep comments from python and have them inserted in the java file.

Thank you for you reply.

Best regards,
 Answer: Will think about those.  Wasn't aware any people used the java skeleton export feature!
Thanks, Andy..Your pyNsource is superb and very helpfule
Posted by Meng on
Nice post. You may be interested by the UML online modeler called GenMyModel. It designs UML-compliant models in a web-browser and generates code. http://www.genmymodel.com
Posted by Basil Peace on
It is worth to mention, which version of Python (2, 3) is supported/required for running.
Posted by pyguy on
Hi does PynSource generate Python code too? I can't find anything in the menus. I was hoping to generate simple stubs from creating a class diagram with this tool. If not, it would be really useful. Thanks!
Posted by Chayma on
Hi, I installed Pynsorce 1.61 but I didn't know how to use it.
Can you help me?
Thank you
Answer: File/Open and select the Python files that you want to convert into UML.


Leave a Reply

(Your email will not be publicly displayed.)

Captcha Code

Click the image to see another captcha.