UML sequence diagrams are useful for describing communication between interacting objects. That said, they are cumbersome to draw and maintain using GUI tools. An alternative approach is to code the interactions which can then be generated into a diagram.
SequencePlot is a Python module for using code to generate a UML sequence diagram. The sequence diagram can be rendered in a svg, ps, or png format.
SequencePlot is built on top of the sequence.pic macros from UMLGraph which in turn use the GNU Plotutils pic2plot utility. SequencePlot treats the pic macros defined in sequence.pic as drawing primitives that are more easily controlled via the object oriented abstractions offered by Python.
- GNU Plotutils
- Python 2.6+
This code is stable enough to draw sequence diagrams. Come in, the water is fine.
- Stable documentation of classes
- Better error handling
- Package the module using standard Python distribution conventions.
- More code examples
-
Make sure the directory holding the module folder
sequenceplotis included in yourPYTHONPATHenvironment variable. -
Enter the following Python code into the file
sd_authenticate.py.from sequenceplot import SequenceObject, SequenceDiagram client = SequenceObject('c: client') server = SequenceObject('s: server') diagram = SequenceDiagram([client, server]) diagram.setParam('objectSpacing', 1.75) diagram.beginFrame(client, 'Login') client.callMethod(server, 'login(username, password)', response='sessionID, userInfo') diagram.endFrame(server) diagram.svg('sd_authenticate') -
Execute the following line:
$ python sd_authenticate.py
The following files will be generated:
sd_authenticate.svg- UML sequence diagram in SVG formatsd_authenticate.pic- UML sequence diagram in pic format
Creating a UML sequence diagram with SequencePlot entails the following steps:
- Import required objects from
sequenceplotmodule. - Instantiate objects with base type
SequenceObject. - Instantiate diagram with type
SequenceDiagram. - Configure diagram object.
- Configure parameters using
diagram.setParam(key, value)
- Configure parameters using
- Define interactions between objects. Common messages sent between objects are:
- Call method on another object. Example:
client.callMethod(target, 'getUserInfo()', 'userInfo') - Create instance of another object. Example:
server.createInstance(hashTable, 'hash table') - Destroy instance of another object. Example:
server.destroyInstance(hashTable)
- Call method on another object. Example:
- Generate the sequence diagram.
- Generate SVG file. Example:
diagram.svg('diagram') - Generate PS file. Example:
diagram.ps('diagram') - Generate PNG file. Example:
diagram.png('diagram') - Emit
piccommands tostdout. Example:diagram.run()
- Generate SVG file. Example:
It is strongly recommended to read the Python source files in the folder examples. They will provide a better understanding of the expressive capabilities of this package.
To generate pydoc HTML, run the following command in the top level directory of this project:
$ make docs
Alternately, to view documentation online:
$ pydoc sequenceplot
$ pydoc sequenceplot.SequenceDiagram
$ pydoc sequenceplot.SequenceObject
To debug the pic files generated by SequencePlot, please refer to the UMLGraph Sequence Diagram documentation.
Copyright 2012 Yummy Melon Software LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Pic macros for drawing UML sequence diagrams
(C) Copyright 2004-2005 Diomidis Spinellis.
Permission to use, copy, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.