Python DSL for writing PlantUML sequence diagram
Project description
Napkin
Python as DSL for writing sequence diagram.
The sequence diagrams are useful tool to capture the S/W design and PlantUML is a great tool to write nice sequence diagrams in plain text.
However, the syntax of PlantUML is quite error prone especially when there are nested calls involved.
For example:
participant User
User -> Foo: DoWork()
activate Foo
Foo -> Foo: InternalCall()
activate Foo
Foo -> Bar: CreateRequest()
activate Bar
Bar --> Foo: Request
deactivate Bar
deactivate Foo
deactivate Foo
By using normal Python code, it can be naturally expressed with 'with' statement as below:
@napkin.seq_diagram()
def sd_simple(c):
user = c.object('User')
foo = c.object('Foo')
bar = c.object('Bar')
with user:
with foo.DoWork():
with foo.InternalCall():
with bar.CreateRequest():
c.ret('Done')
Basically, sequence diagram is expressed as methods calls between objects.
There are several advantages of using Python as DSL:
- Easy to write correct diagrams
- Many common mistakes are detected as normal Python error. For example, method call to an undefined object will be just normal Python error.
- Any Python editor can become sequence diagram editor
Installation
Install and update using pip
pip install -U napkin
Hello world
Write a simple script called hello.py as follows:
import napkin
@napkin.seq_diagram
def hello_world(c):
user = c.object('user')
world = c.object('world')
with user:
world.hello()
Then, the following command will generate hello_world.uml:
$ napkin hello.py
More examples
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file napkin-0.5.0.tar.gz
.
File metadata
- Download URL: napkin-0.5.0.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
7f2dfcbb89dd74c1a09ded8fe7e1fa0e663ce63d1cee83ca61672366e23c5675
|
|
MD5 |
21bcfe7f3e0914059088fef8076b86c1
|
|
BLAKE2b-256 |
c481ff431fd803c1726ea1bbf7cd82009854a213f75b7b2bbb19cdb53da8d0a1
|
File details
Details for the file napkin-0.5.0-py3-none-any.whl
.
File metadata
- Download URL: napkin-0.5.0-py3-none-any.whl
- Upload date:
- Size: 14.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
273ed63b443b990d073972f4a4085502d87c6147e6c8c31b2032c0fb91305c80
|
|
MD5 |
f7031c18b7da73b043bda538d960b1b6
|
|
BLAKE2b-256 |
75a714a8c981e17ffa0abe3df8667141114551ebc56d3f2315bffe3b955ebdb5
|
File details
Details for the file napkin-0.5.0-py2-none-any.whl
.
File metadata
- Download URL: napkin-0.5.0-py2-none-any.whl
- Upload date:
- Size: 14.1 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/2.7.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
afc34296520070b674a2f31790f19e8e6a2eca2a854b008e862f7002f2e4f797
|
|
MD5 |
9c24027f3d587b5aba61f6d4402b3f5f
|
|
BLAKE2b-256 |
09199fe5e1151ee9849d29c36e5ef308c5b202b2e0f72ed7c07999a10fd802aa
|