Skip to main content

Python codes to Flowcharts.

Project description

PyFlowchart

PyFlowchart is a package to:

  • write flowchart in Python,
  • translate Python source codes into flowchart.

PyFlowchart produces flowcharts in flowchart.js flowchart DSL, a widely used flow chart textual representation. It's easy to convert these flowcharts text into a picture via flowchart.js.org, francoislaberge/diagrams, or some markdown editors.

Get PyFlow

$ pip3 install pyflowchart

Flowchart in Python

PyFlowchart including flowchart.js node types:

  • StartNode
  • OperationNode
  • ConditionNode
  • InputOutputNode
  • SubroutineNode
  • EndNode

Nodes can be connected by connect() method (connect_{yes|no} for ConditionNode).

Get a Flowchart with your start node and call its flowchart() method to generate flowchart.js flowchart DSL:

from pyflowchart import *

st = StartNode('a_pyflow_test')
op = OperationNode('do something')
cond = ConditionNode('Yes or No?')
io = InputOutputNode(InputOutputNode.OUTPUT, 'something...')
sub = SubroutineNode('A Subroutine')
e = EndNode('a_pyflow_test')

# define the direction the connection will leave the node from
sub.set_connect_direction("right")
    
st.connect(op)
op.connect(cond)
cond.connect_yes(io)
cond.connect_no(sub)
sub.connect(op)
io.connect(e)
 
fc = Flowchart(st)
print(fc.flowchart())

Output:

st4471442960=>start: start a_pyflow_test
op4471442064=>operation: do something
cond4471501392=>condition: Yes or No?
io4471501648=>inputoutput: output: something...
e4471501904=>end: end a_pyflow_test
sub4471501584=>subroutine: A Subroutine

st4471442960->op4471442064
op4471442064->cond4471501392
cond4471501392(yes)->io4471501648
io4471501648->e4471501904
cond4471501392(no)->sub4471501584
sub4471501584(right)->op4471442064

Go http://flowchart.js.org and translate the generated textual representation into SVG flow chart diagrams:

screenshot on flowchart.js page

P.S. Many Markdown editors (for example, Typora) support this flowchart syntax, too. And if you prefer CLI, see francoislaberge/diagrams.

Python to Flowchart

PyFlowchart can also translate your Python Codes into Flowcharts.

For example, you got a simple.py:

def foo(a, b):
    if a:
        print("a")
    else:
        for i in range(3):
            print("b")
    return a + b

Run PyFlowchart in CLI to generate flowchart code:

$ python3 -m pyflowchart simple.py

# output flowchart code.

Or, in Python

>>> from pyflowchart import Flowchart
>>> with open('simple.py') as f:
...     code = f.read()
... 
>>> fc = Flowchart.from_code(code)
>>> print(fc.flowchart())

# output flowchart code.

result

Beautify Flowcharts

Modify the generated flowchart code by yourself.

License

Copyright 2020 CDFMLR. All rights reserved.

Licensed under the MIT License.

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

pyflowchart-0.0.1.tar.gz (10.3 kB view details)

Uploaded Source

File details

Details for the file pyflowchart-0.0.1.tar.gz.

File metadata

  • Download URL: pyflowchart-0.0.1.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.6

File hashes

Hashes for pyflowchart-0.0.1.tar.gz
Algorithm Hash digest
SHA256 1807b69c6938651d021abd3703eba3c53cb68726bd55112da7bd85ba1b5a48d2
MD5 bc987ec3e287a383c307e09dd0fe3810
BLAKE2b-256 468da41f80848d9de98b524fe69730b47c7842dca6f5d6580cc798f08e92b481

See more details on using hashes here.

Supported by

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