Flow Diagram/Sequence Diagram Creation Python Library
Table of Content:
Overview
FlowDiagram is a Python Library to create Sequence Diagram in Command Line or Image (.PNG)
Setup
Installtion via PIP:
pip install flowdiagram
Manual Installation:
-
This package requires:
- multipledispatch==0.6.0
- six==1.16.0
- Pillow==8.2.0
-
First install above packages.
-
Download tar.gz from pypi and untar it.
-
Go to untarred directory.
-
Execute below command:
python setup.py install
Usage
Using this library we can generate Sequence Diagram on Command Line or a Image (.PNG) via both python script or flow text file.
Generate Sequence Diagram via flow text file
Flow Text File Example:
title Example Flow
Bob->Alice: Hi! Alice
Alice->Bob: Hi! Bob
Bob->Alice: '''Are you free?
tomorrow'''
Alice->Bob: I think so, why?
Bob->Alice: Want to see a movie?
Alice->Bob: Sure.
Bob->Alice: Great!
Alice->Bob: See you later.
Bob->Alice: Bye.
The -> is used to draw a message between two
participants.
Participants do not have to be explicitly declared.
To have a dotted arrow, you use -->
NOTE Do not use --> or <- or <-- instead of ->.
This will impact flow diagram.
To provide multiple line message please start and end message with '''
For Example:
Bob->Alice: '''Are you free?
tomorrow'''
NOTE if a single line message will be sliced into multiple line as per the flow diagram size requirements.
To execute module use below command:
python -m flowdiagram create
Example :
linus> python -m flowdiagram create
[Flowdiagram] Please Provide Flow File Path (i.e. .txt file) : callflow.txt
[Flowdiagram] What you want to do create ?
[Flowdiagram] 1 : Create Flow on command line
[Flowdiagram] 2 : Create Flow picture
[Flowdiagram] 3 : Exit
[Flowdiagram] Your Choice : 1
[Flowdiagram] Reading File......
Example Flow
Bob Alice
| |
|Hi! Alice |
|---------------------------->|
| |
|Hi! Bob |
|<----------------------------|
| |
|Are you free? |
|tomorrow |
|---------------------------->|
| |
|I think so, why? |
|<----------------------------|
| |
|Want to see a movie? |
|---------------------------->|
| |
|Sure. |
|<----------------------------|
| |
|Great! |
|---------------------------->|
| |
|See you later. |
|<----------------------------|
| |
|Bye. |
|---------------------------->|
| |
Generate Sequence Diagram via python script
Test Script Example:
>>> from flowdiagram import flowdiagram
>>>
>>> sqd = flowdiagram()
>>> sqd.setTitle('Script Flow Example')
>>>
>>>
>>> sqd.addFlow(['Node 1','Node 2','First message'])
>>> sqd.addFlow(['Node 2','Node 1','Second message'])
>>> sqd.addFlow(['Node 1','Node 2','Third message'])
>>> sqd.addFlow(['Node 2','Node 2','Really Long long long long long long long long long message'])
>>> sqd.addFlow(['Node 2','Node 2','Really Long long long long long long and \nmulti line message'])
>>> sqd.addFlow(['Node 1','Node 2','Really Long long long long long long and \nmulti line message'])
>>> sqd.addFlow(['Node 1','Node 1','Really Long long long long long long and \nmulti line message'])
>>> sqd.addFlow(['Node 1','Node 1','Really Long long long long long long long long long message'])
>>> sqd.addFlow(['Node 1','Node 2','Second last message'])
>>> sqd.addFlow(['Node 2','Node 1','Last message \n BYE BYE!!!!!'])
>>>
>>> sqd.drawCmdLine()
Output:
Script Flow Example
Node 1 Node 2
| |
|First message |
|---------------------------------------------------->|
| |
|Second message |
|<----------------------------------------------------|
| |
|Third message |
|---------------------------------------------------->|
| |
| |Really Long long long long long long long lo
| |ng long message
| |---
| | |
| |<--
| |
| |
| |Really Long long long long long long and
| |multi line message
| |---
| | |
| |<--
| |
| |
|Really Long long long long long long and |
|multi line message |
|---------------------------------------------------->|
| |
|Really Long long long long long long and |
|multi line message |
|--- |
| | |
|<-- |
| |
|Really Long long long long long long long lo |
|ng long message |
|--- |
| | |
|<-- |
| |
|Second last message |
|---------------------------------------------------->|
| |
|Last message |
| BYE BYE!!!!! |
|<----------------------------------------------------|
| |
To create image from the flow use drawPicture() method
>>> from flowdiagram import flowdiagram
>>>
>>> sqd = flowdiagram()
>>> sqd.addTitle('Example Flow')
>>> sqd.addFlow(['Bob','Alice','Hi! Alice'])
>>> sqd.addFlow(['Alice','Bob','Hi! Bob'])
>>> sqd.addFlow(['Bob','Alice','Are you free? \ntomorrow'])
>>> sqd.addFlow(['Alice','Bob','I think so, why?'])
>>> sqd.addFlow(['Bob','Alice','Want to see a movie?'])
>>> sqd.addFlow(['Alice','Bob','Sure .'])
>>> sqd.addFlow(['Bob','Alice','Great !'])
>>> sqd.addFlow(['Alice','Bob','See You later'])
>>> sqd.addFlow(['Bob','Alice','Bye .'])
>>> sqd.drawPicture()
[Flowdiagram] File created Successfully...
[Flowdiagram] Path : C:\Users\myUser\Flowdiagram.png
>>>
Output:
Methods
flowdiagram class consists of below methods:
flowdiagram.setTitle(str)
This method is used to set the title of the Sequence/Flow Diagram. For Example:
>>> from flowdiagram import flowdiagram
>>> sqd = flowdiagram()
>>> sqd.setTitle('Script Flow Example')
flowdiagram.addFlow(list)
This method is used to add flow of the Sequence/Flow Diagram.
Format of the list is ['source','destination','message']
NOTE if you want to add multiple lines message just add '\n' for next line.
For Example:
>>> from flowdiagram import flowdiagram
>>> sqd = flowdiagram()
>>> sqd.setTitle('Script Flow Example')
>>> sqd.addFlow(['Node 1','Node 2','First message \nmulti line'])
flowdiagram.drawCmdLine()
This method is used to draw Sequence/Flow Diagram of added flow on command line. For Example:
>>> from flowdiagram import flowdiagram
>>> sqd = flowdiagram()
>>> sqd.setTitle('Script Flow Example')
>>> sqd.addFlow(['Node 1','Node 2','First message'])
>>> sqd.addFlow(['Node 2','Node 1','Second message'])
>>> sqd.drawCmdLine()
Script Flow Example
Node 1 Node 2
| |
|First message |
|---------------------------------------------------->|
| |
|Second message |
|<----------------------------------------------------|
| |
flowdiagram.drawCmdLine(str)
This method is used to draw Sequence/Flow Diagram of added flow on command line via file. This method takes file path as an argument. File content [Example](#Generate Sequence Diagram via flow text file) For Example:
>>> from flowdiagram import flowdiagram
>>> sqd = flowdiagram()
>>> myFile = 'C:\\Users\\myUser\\callflow.txt'
>>> sqd.drawCmdLine(myFile)
Script Flow Example
Node 1 Node 2
| |
|First message |
|---------------------------------------------------->|
| |
|Second message |
|<----------------------------------------------------|
| |
flowdiagram.drawPicture()
This method is used to create IMAGE of Sequence/Flow Diagram of added flow. For Example:
>>> from flowdiagram import flowdiagram
>>> sqd = flowdiagram()
>>> sqd.setTitle('Script Flow Example')
>>> sqd.addFlow(['Node 1','Node 2','CER'])
>>> sqd.addFlow(['Node 2','Node 1','CEA'])
>>> sqd.addFlow(['Node 1','Node 2','CCR-I'])
>>> sqd.addFlow(['Node 2','Node 1','CCA-I'])
>>> sqd.addFlow(['Node 1','Node 2','CCR-T'])
>>> sqd.addFlow(['Node 2','Node 1','CCA-T'])
>>> sqd.addFlow(['Node 1','Node 2','DPR'])
>>> sqd.addFlow(['Node 2','Node 1','DPA'])
>>> sqd.drawPicture()
[Flowdiagram] File created Successfully...
[Flowdiagram] Path : C:\Users\myUser\Flowdiagram.png
>>>
flowdiagram.drawPicture(str)
This method is used to create IMAGE of Sequence/Flow Diagram of added flow on command line via file. This method takes file path as an argument. File content [Example](#Generate Sequence Diagram via flow text file) For Example:
>>> from flowdiagram import flowdiagram
>>> sqd = flowdiagram()
>>> myFile = 'C:\\Users\\myUser\\callflow.txt'
>>> sqd.drawPicture(myFile)
[Flowdiagram] File created Successfully...
[Flowdiagram] Path : C:\Users\myUser\Flowdiagram.png
>>>
Metadata
Release files for flowdiagram 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| flowdiagram-1.0.0.tar.gz | 10.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| flowdiagram-1.0.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 19.5 kB
Release files / flowdiagram-1.0.0.tar.gz
| Download URL | flowdiagram-1.0.0.tar.gz |
|---|---|
| Size | 10.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
db9e802199bcfd8762ba741608d7296a2a62b07f2ed818a99cd0ea06020af605
|
|
BLAKE2b-256 checksum How to use checksums |
95a3219091b49377b294d5baf3e6fab0101b886d00df30d20ee5335cb7298a89
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.1
|
Release files / flowdiagram-1.0.0-py2.py3-none-any.whl
| Download URL | flowdiagram-1.0.0-py2.py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
0f2538f28eeb87b3ec608d83b437f5f442cf02e8cb0b6773ee73a1df034491d8
|
|
BLAKE2b-256 checksum How to use checksums |
ca5c584f1bb956344ae81e0b40ff50966e7c61d024d2b6cb4c0784ba8818d594
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.1
|