Skip to main content

Language for ASCII diagrams.

Project description

PyPI Build Coverage Status Python Documentation

ADia

ADia is a language specially designed to render ASCII diagrams.

Currently, only sequence diagrams are supported, but the roadmap is to support two more types of diagrams: fork and class, check out the TODO.md to figure out what I talking about.

The ADia can also run flawlessly inside the browsers using the awesome project: Brython. check out the Web Interface section below for more info.

diagram: Foo
sequence:
foo -> bar: Hello World!

Output:

 DIAGRAM: Foo                             

 +-----+             +-----+
 | foo |             | bar |
 +-----+             +-----+
    |                   |
    |~~~Hello World!~~~>|
    |                   |
    |<------------------|
    |                   |
 +-----+             +-----+
 | foo |             | bar |
 +-----+             +-----+

Command line

adia << EOF
diagram: Foo
sequence:
foo -> bar: Hello
EOF

Or feed one or more filename(s):

adia file1 file2 fileN

Use adia --help for more info.

Python API

from adia import Diagram

diagram = Diagram('''
  diagram: Foo
  sequence:
  foo -> bar: Hello World!
''')

print(diagram.renders())

Web interface

The adia package should be compatible with the Brython too. So, you can use it on every browser which supports ECMA6.

To build and check the demo, run:

make clean
make www
make serve

Or just one line to do all the above commands in order:

make clean serve

then open http://localhost:8000 in your favorite browser to use adia wihtout the CPython.

Isn't that nice?

Setup development environment

Use your favorite virtual environment tool such as https://pypi.org/project/virtualenvwrapper/.

Then:

make env

Running tests

CPython Tests

make test

CPython Coverage

make cover

Brython Tests

make clean serve

Then open the browser and point http://localhost:8000/check.html to run tests.

Update Brython runtime

Run make cleanall to force download and update brython*.js files.

make cleanall
make www

Complete example

diagram: Authentication
version: 1.0
author: pylover

sequence: Login/Logout
alice.title: Alice
bob.title: Bob
db.title: Database

# Login
@alice ~ bob: Alice tries to authenticate herself
alice -> bob: authenticate(email, password) -> token
  if: db is null
    bob -> db: initialize() -> db
  elif: db.is_connected()
    bob -> db: keepalive()
  else:
    while: not db.is_connected()
      bob -> db: connect()
  
  bob -> bob: create_token() -> token
  
@alice: |
  Alice decides to 
  store the newly 
  received Token 
  in a safe place. 
alice -> alice: store(token)

# Logout
@alice ~ bob: Alice tries to logout
alice -> bob: logout(token)
  bob -> db: delete(token)
  for: each token in db
    bob -> db: delete(token)

Generated diagram:

  DIAGRAM: Authentication                                                    
  author: pylover                                                            
  version: 1.0                                                               
                                                                             
                                                                             
  SEQUENCE: Login/Logout                                                     
                                                                             
  +-------+                             +-----+                 +-----------+
  | Alice |                             | Bob |                 | Database  |
  +-------+                             +-----+                 +-----------+
      |                                    |                          |      
  ---------------------------------------------                       |      
  | Alice tries to authenticate herself       |                       |      
  ---------------------------------------------                       |      
      |                                    |                          |      
      |~~~authenticate(email, password)~~~>|                          |      
      |                                    |                          |      
      |                                 *************************************
      |                                 * if db is null                     *
      |                                 *************************************
      |                                    |                          |      
      |                                    |~~~initialize()~~~~~~~~~~>|      
      |                                    |                          |      
      |                                    |<--db---------------------|      
      |                                    |                          |      
      |                                 *************************************
      |                                 * elif db.is_connected()            *
      |                                 *************************************
      |                                    |                          |      
      |                                    |~~~keepalive()~~~~~~~~~~~>|      
      |                                    |                          |      
      |                                    |<-------------------------|      
      |                                    |                          |      
      |                                 *************************************
      |                                 * else                              *
      |                                 *************************************
      |                                 *************************************
      |                                 * while not db.is_connected()       *
      |                                 *************************************
      |                                    |                          |      
      |                                    |~~~connect()~~~~~~~~~~~~~>|      
      |                                    |                          |      
      |                                    |<-------------------------|      
      |                                    |                          |      
      |                                 *************************************
      |                                 * end while                         *
      |                                 *************************************
      |                                 *************************************
      |                                 * end if                            *
      |                                 *************************************
      |                                    |                          |      
      |                                    |~~~create_token()~~~+     |      
      |                                    |                    |     |      
      |                                    |<--token------------+     |      
      |<--token----------------------------|                          |      
      |                                    |                          |      
  --------------------                     |                          |      
  | Alice decides to |                     |                          |      
  | store the newly  |                     |                          |      
  | received Token   |                     |                          |      
  | in a safe place. |                     |                          |      
  --------------------                     |                          |      
      |                                    |                          |      
      |~~~store(token)~~~+                 |                          |      
      |                  |                 |                          |      
      |<-----------------+                 |                          |      
      |                                    |                          |      
  ---------------------------------------------                       |      
  | Alice tries to logout                     |                       |      
  ---------------------------------------------                       |      
      |                                    |                          |      
      |~~~logout(token)~~~~~~~~~~~~~~~~~~~>|                          |      
      |                                    |~~~delete(token)~~~~~~~~~>|      
      |                                    |                          |      
      |                                    |<-------------------------|      
      |                                    |                          |      
      |                                 *************************************
      |                                 * for each token in db              *
      |                                 *************************************
      |                                    |                          |      
      |                                    |~~~delete(token)~~~~~~~~~>|      
      |                                    |                          |      
      |                                    |<-------------------------|      
      |                                    |                          |      
      |                                 *************************************
      |                                 * end for                           *
      |                                 *************************************
      |                                    |                          |      
      |<-----------------------------------|                          |      
      |                                    |                          |      
  +-------+                             +-----+                 +-----------+
  | Alice |                             | Bob |                 | Database  |
  +-------+                             +-----+                 +-----------+
                                                                             

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

adia-0.1.2.tar.gz (20.6 kB view hashes)

Uploaded Source

Built Distribution

adia-0.1.2-py3.8.egg (51.6 kB view hashes)

Uploaded Source

Supported by

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