#Write a Flow in Python
Use jiggy-flow to receive a host invocation and return a result from Python.
Callers use the same input and result boundary for Python, TypeScript, and Markdown methods.
The illustrative classifier recognizes a few words and suggests a support queue. The application owns any routing or assignment that follows.
#What you need
The SDK requires Python 3.11 or newer and has no runtime dependencies. Execution also needs a host that supports Python and the package's dependencies. Jig's current alpha supports Markdown and TypeScript, so use the local SDK check below for this Python example. The support reference separates SDK availability from qualified host support.
#Install the SDK
Create a virtual environment:
Activate it with source .venv/bin/activate on Linux or macOS.
In Windows PowerShell, use .venv\Scripts\Activate.ps1.
Then install the latest published prerelease from PyPI:
This guide describes the current source interface. To qualify an unpublished candidate, install its matching built wheel. Use the revision qualified by your selected host when integrating an application.
#Write the method
Save this as FLOW.py:
handle() is the synchronous entrypoint that owns the event loop and serves one invocation.
Call it at process entry, outside an existing asyncio loop.
The handler returns portable data or raises an operational error.
For input {"message":"I was charged twice."}, the method returns:
For {"message":12}, the handler raises INVALID_INPUT.
Outcomes and failures explains how callers handle these distinct responses.
#Check it locally
Follow Exercise an installed SDK with this FLOW.py and its classifier input.
That complete POSIX exercise supplies a Run/0 request and checks the process response.
Use it for trusted local code and SDK qualification.
It provides neither host containment nor application permissions.
Starting python FLOW.py alone waits for the protocol request on stdin.
A production application invokes the method through a host's supported execution interface.
The host prepares the interpreter, dependencies, authority, deadline, and cleanup.
#Make it useful for your task
Add refund to the billing words.
Repeat the local check with {"message":"Please refund my order."}.
The queue changes from manual to billing.
Test representative messages before relying on the classifier's suggestions.
Keep this method's implementation in FLOW.py.
Optional FLOW.meta.json describes its purpose and declared dependencies.
Optional FLOW.contract.json adds input/result validation, custom outcomes, or ports when needed.
Package/0 defines their exact formats.
#Build on the result
Use context.call() for host-bound dependencies, and inspect each returned outcome before using its output.
Await owned calls before returning your result.
The composition guide explains the shared calling model.
Root cancellation reaches the handler as asyncio.CancelledError.
Use try/finally for local cleanup and propagate cancellation.
The host enforces deadlines and settles execution.
After handle() starts, ordinary print() diagnostics go to stderr.
Keep raw writes and import-time logging off protocol stdout.
The SDK reference covers settings, attachments, errors, channels, and cancellation in both languages.