
A flowchart is a visual illustration of a process. It uses a set of symbols, e.g., boxes, diamonds, and arrows, to demonstrate the steps involved and the decisions that need to be made at each stage.
This article covers the following topics:
Python Flowchart Maker API
Aspose.Diagram for Python is a library that empowers programmers to create, edit, and manipulate Visio files directly within their Python applications. It provides a set of APIs for working with Visio files. We will use it to create a flowchart programmatically in Python.
Please download the package or install the API from PyPI using the following pip command in the console:
pip install aspose-diagram-python
Create Flowchart Programmatically in Python
We can easily make a flowchart in Python by following the steps below:
- Create the schema for the diagram.
- Load the master for adding shapes using the Diagram class.
- Create shapes using the Shape class.
- Add shapes to the diagram using the add_shape() method.
- Add shape connectors using the connect_shapes_via_connector() method.
- Set the diagram layout using the LayoutOptions class.
- After that, specify save options using the DiagramSaveOptions class.
- Finally, save the output file in VSDX format using the save() method.
The following code sample shows how to create a flowchart diagram in Python.
# This code sample demonstartes how to create a flowchart in Python. | |
import aspose.diagram | |
from aspose.diagram import * | |
def createFlowChart(): | |
# schema for the diagram to be created | |
diagram_object = Input( | |
input_rectangles=[ | |
InputRectangle("A", "Manager"), | |
InputRectangle("B", "Team Leader"), | |
InputRectangle("C", "Team Member"), | |
InputRectangle("D", "Team Member"), | |
InputRectangle("E", "Team Member") | |
], | |
input_connectors=[ | |
InputConnector("A", "B"), | |
InputConnector("B", "C"), | |
InputConnector("B", "D"), | |
InputConnector("B", "E") | |
] | |
) | |
diagram = Diagram("D:\\Files\\BasicShapes.vss") | |
page = diagram.pages[0] | |
shape_names = {} | |
# Adding shapes and connectors from the schema | |
for rectangle in diagram_object.InputRectangles: | |
shape = Shape() | |
shape_id = diagram.add_shape(shape, "Rectangle", 0) | |
shape_names[rectangle.Name] = shape_id | |
shape = page.shapes.get_shape(shape_id) | |
shape.text.value.add(Txt(rectangle.Text)) | |
for connector in diagram_object.InputConnectors: | |
connector_id = diagram.add_shape(Shape(), "Dynamic connector", 0) | |
page.connect_shapes_via_connector( | |
shape_names[connector.OriginShapeName], | |
aspose.diagram.manipulation.ConnectionPointPlace.RIGHT, | |
shape_names[connector.DestinationShapeName], | |
aspose.diagram.manipulation.ConnectionPointPlace.LEFT, | |
connector_id | |
) | |
layout_options = aspose.diagram.autolayout.LayoutOptions() | |
layout_options.layout_style = aspose.diagram.autolayout.LayoutStyle.FLOW_CHART | |
layout_options.direction = aspose.diagram.autolayout.LayoutDirection.LEFT_TO_RIGHT | |
layout_options.space_shapes = 5.0 | |
layout_options.enlarge_page = True | |
diagram.layout(layout_options) | |
page.page_sheet.print_props.print_page_orientation.value = PrintPageOrientationValue.LANDSCAPE | |
save_options = aspose.diagram.saving.DiagramSaveOptions() | |
save_options.save_format = SaveFileFormat.VSDX | |
save_options.auto_fit_page_to_drawing_content = True | |
diagram.save("D:\\Files\\flowchart_output.vsdx", save_options) | |
class Input: | |
def __init__(self, input_rectangles=None, input_connectors=None): | |
self.InputRectangles = input_rectangles if input_rectangles else [] | |
self.InputConnectors = input_connectors if input_connectors else [] | |
class InputRectangle: | |
def __init__(self, name, text): | |
self.Name = name | |
self.Text = text | |
class InputConnector: | |
def __init__(self, origin_shape_name, destination_shape_name): | |
self.OriginShapeName = origin_shape_name | |
self.DestinationShapeName = destination_shape_name | |
createFlowChart() |

Get Free API License
You can get a free temporary license in order to use the API without evaluation limitations.
Flowchart Python Programming – Free Resources
You can learn more about flowchart Python programming and explore various other features of the library using the resources below:
Conclusion
In this article, you have learned how to create a flowchart programmatically in Python. By leveraging Aspose.Diagram for Python, you can create various types of flowcharts using different types of shapes, like the decision or process, as well as different layouts, like left to right or right to left, etc. In case of any ambiguity, please contact us on our free support forum.