Skip to main content

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

See example

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

napkin-0.5.1.tar.gz (10.6 kB view details)

Uploaded Source

Built Distributions

napkin-0.5.1-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

napkin-0.5.1-py2-none-any.whl (14.1 kB view details)

Uploaded Python 2

File details

Details for the file napkin-0.5.1.tar.gz.

File metadata

  • Download URL: napkin-0.5.1.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/2.7.15

File hashes

Hashes for napkin-0.5.1.tar.gz
Algorithm Hash digest
SHA256 6e49896ca6aec5ad25cafd8823a8369d21d7fb4464158b704dd000e80dc49862
MD5 ea7949d6a6932b717b3bf4da599afab6
BLAKE2b-256 28865c095f96b2623149350fea6b7cf46818a0bf782cf948cd2c70c97de5e780

See more details on using hashes here.

File details

Details for the file napkin-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: napkin-0.5.1-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/2.7.15

File hashes

Hashes for napkin-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fcbaf3bbefe2237cf04671da8d5bb54b2f9e87268016074656a1bc23641fba9a
MD5 d751e14119d8928593779f52fe0837c4
BLAKE2b-256 982181f00d5864d28e1af80bfa8b588bfa7bf3e27bd10f27570f9e325859bbb4

See more details on using hashes here.

File details

Details for the file napkin-0.5.1-py2-none-any.whl.

File metadata

  • Download URL: napkin-0.5.1-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

Hashes for napkin-0.5.1-py2-none-any.whl
Algorithm Hash digest
SHA256 1c8cce637cc904c924d0b4adcade70ce3127fe0991883931e521e7707608b9e7
MD5 d3d3b91f01c6a7e6304f656e8023a023
BLAKE2b-256 25e778ffb7edcf1f856bc9ec3d31e75a15363d688e10f7e293aa4721462fa5c4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page