Python BPMN: Running Workflows in Python

Python BPMN means modeling and running BPMN business processes in Python. You express the process — its tasks, gateways, and events — and a Python engine executes it: tracking state, routing work, and waiting for people or timers.

BPMN (Business Process Model and Notation) is the standard notation for business processes. Designers usually draw it and store it as XML. In Python you choose: import that XML, or write the process as code. This article covers both, and how the concepts line up.

How BPMN Concepts Map to Python

BPMN has a small vocabulary. Each element maps one-to-one to code, so a diagram and a Python class describe the same thing.

BPMN element In Python (Viewflow)
Start / End event flow.Start / flow.End
User task flow.View — a Django view a person completes
Service task flow.Function — inline Python code, or a Celery job
Exclusive gateway flow.If / flow.Switch
Parallel gateway flow.Split / flow.Join

Because the mapping is one-to-one, you lose nothing by writing the process as code — and you gain everything Python gives you around it.

Two Ways to Run BPMN in Python

Import the XML. Some engines load a .bpmn file a designer produced and interpret it at runtime. The diagram stays the source of truth. This suits teams where analysts own the process and developers wire in the tasks.

Write it as code. Others define the process as a Python class. The code is the source of truth, and the engine renders the diagram from it. This suits engineering teams who want the process in version control, under test, and open to their tools. See Python-Native BPMN for why this matters.

Both are “Python BPMN”. The difference is which artifact leads — the drawing or the code.

Running a BPMN Workflow with Viewflow

Viewflow is an open-source BPMN engine for Django that takes the code-first route. You write the Flow class; Viewflow executes it and renders the diagram from the same source.

from viewflow import this
from viewflow.workflow import flow
from . import models, views

class ShipmentFlow(flow.Flow):
    process_class = models.ShipmentProcess

    start = flow.Start(views.OrderView.as_view()).Next(this.split)
    split = flow.Split().Next(this.pack).Next(this.invoice)
    pack = flow.View(views.PackView.as_view()).Next(this.join)
    invoice = flow.View(views.InvoiceView.as_view()).Next(this.join)
    join = flow.Join().Next(this.ship)
    ship = flow.View(views.ShipView.as_view()).Next(this.end)
    end = flow.End()

Packing and invoicing run in parallel after the split, then the join waits for both before shipping. The engine persists every step, so the process resumes after a restart or a long wait.

Common Questions

What is Python BPMN?

Python BPMN is the modeling and execution of BPMN business processes in Python. You describe the process — tasks, gateways, and events — and a Python workflow engine runs it, keeping the state and routing work between people and systems.

Can I run BPMN workflows in Python?

Yes. Python workflow engines run BPMN processes either by importing BPMN XML or by defining the process as Python code. Viewflow takes the code-first route: you write a Flow class and run it in production with parallel tasks and persistence.

How do BPMN elements map to Python code?

Each BPMN element becomes a node in a Python Flow class. Start and end events, user and service tasks, and exclusive or parallel gateways all have a direct code node. The diagram and the class describe the same process.

Do I need to draw a BPMN diagram to run a workflow in Python?

No. With a code-first engine you write the process as a Python class, and the engine generates the diagram from it. You get the picture for free without drawing it, and it never drifts out of sync with the code that runs.

Next Steps