[PR #28] [MERGED] feat: add WorkflowServer to serve workflows as web services #59

Closed
opened 2026-02-16 02:16:25 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/run-llama/workflows-py/pull/28
Author: @masci
Created: 7/22/2025
Status: Merged
Merged: 7/25/2025
Merged by: @masci

Base: mainHead: massi/serve


📝 Commits (10+)

📊 Changes

14 files changed (+1809 additions, -3 deletions)

View changed files

📝 .github/workflows/test.yml (+2 -2)
CLAUDE.md (+52 -0)
examples/server/fastapi_server_example.ipynb (+314 -0)
examples/server/server_example.ipynb (+426 -0)
📝 pyproject.toml (+8 -1)
src/workflows/server/__init__.py (+8 -0)
src/workflows/server/server.py (+231 -0)
src/workflows/server/utils.py (+12 -0)
tests/server/__init__.py (+0 -0)
tests/server/conftest.py (+57 -0)
tests/server/test_server.py (+95 -0)
tests/server/test_server_endpoints.py (+406 -0)
tests/server/test_utils.py (+46 -0)
📝 uv.lock (+152 -0)

📄 Description

Serve workflows as web services with HTTP endpoints, real-time event streaming, and support for custom StartEvent objects.

WorkflowServer:

  • exposes HTTP endpoints for workflow execution, based on Starlette
  • can be integrated in existing ASGI applications (e.g. FastAPI) or run standalone using uvicorn under the hood
  • supports both synchronous (/workflows/{name}/run) and asynchronous (/workflows/{name}/run-nowait) execution

Event Streaming:

  • /events/{handler_id} endpoint for streaming workflow events in real-time
  • supports both NDJSON and Server-Sent Events (SSE) formats

Custom StartEvent Support:

  • Accepts custom StartEvent objects via start_event parameter containing the serialized event instance

Dependencies Added:

  • starlette>=0.39.0
  • uvicorn>=0.32.0
  • httpx>=0.25.0 for the testing client (dev dependency)

API Endpoints

Method Endpoint Description
GET /health Health check
GET /workflows List available workflows
POST /workflows/{name}/run Execute workflow synchronously
POST /workflows/{name}/run-nowait Execute workflow asynchronously
GET /results/{handler_id} Get async workflow result
GET /events/{handler_id} Stream workflow events (NDJSON/SSE)

Example Usage

# Server setup
server = WorkflowServer()
server.add_workflow("greeting", GreetingWorkflow())
await server.serve(host="0.0.0.0", port=8000)

# Client usage with custom StartEvent
curl -X POST http://localhost:8000/workflows/greeting/run \
  -H "Content-Type: application/json" \
  -d '{"start_event": "{\"__is_pydantic\": true, \"value\": {\"_data\": {\"name\": \"Alice\"}}, \"qualified_name\": \"workflows.events.StartEvent\"}"}'

# Event streaming
curl http://localhost:8000/events/{handler_id}?sse=true

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/run-llama/workflows-py/pull/28 **Author:** [@masci](https://github.com/masci) **Created:** 7/22/2025 **Status:** ✅ Merged **Merged:** 7/25/2025 **Merged by:** [@masci](https://github.com/masci) **Base:** `main` ← **Head:** `massi/serve` --- ### 📝 Commits (10+) - [`2d861ce`](https://github.com/run-llama/workflows-py/commit/2d861ce8d450770a680095e1fc233f1fc6a437f9) feat: add WorkflowServer to serve workflows as web services - [`50d8765`](https://github.com/run-llama/workflows-py/commit/50d87656dd5f5fb305c52872d0e0fe86daf32cf7) add serve() method to start uvicorn - [`810ee75`](https://github.com/run-llama/workflows-py/commit/810ee75407baab5e85cdecc4679485d5570cbf85) add license headers - [`c2a5356`](https://github.com/run-llama/workflows-py/commit/c2a53562cf1910ed83b3d76a68159c88174db1a6) add tests - [`a59a8b4`](https://github.com/run-llama/workflows-py/commit/a59a8b408f79d5829fa57ed10e544149d3aaa583) add unit tests - [`608bf41`](https://github.com/run-llama/workflows-py/commit/608bf41ab656d3ba6929e01d21d64bcbc62c7ceb) fix linter - [`d23ba21`](https://github.com/run-llama/workflows-py/commit/d23ba213a3157500d2fdb903c3e7c492915fd5ab) fix for python 3.9 - [`01f7a49`](https://github.com/run-llama/workflows-py/commit/01f7a4900149e941bd44f805a7b7045c930a6ab6) add event streaming endpoint - [`82ba374`](https://github.com/run-llama/workflows-py/commit/82ba3743bef356f4b8a363b0610fe355bd338326) fix linter - [`710514f`](https://github.com/run-llama/workflows-py/commit/710514f3b659c0bfb345b8eb899fc832491f5477) add SSE support ### 📊 Changes **14 files changed** (+1809 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `.github/workflows/test.yml` (+2 -2) ➕ `CLAUDE.md` (+52 -0) ➕ `examples/server/fastapi_server_example.ipynb` (+314 -0) ➕ `examples/server/server_example.ipynb` (+426 -0) 📝 `pyproject.toml` (+8 -1) ➕ `src/workflows/server/__init__.py` (+8 -0) ➕ `src/workflows/server/server.py` (+231 -0) ➕ `src/workflows/server/utils.py` (+12 -0) ➕ `tests/server/__init__.py` (+0 -0) ➕ `tests/server/conftest.py` (+57 -0) ➕ `tests/server/test_server.py` (+95 -0) ➕ `tests/server/test_server_endpoints.py` (+406 -0) ➕ `tests/server/test_utils.py` (+46 -0) 📝 `uv.lock` (+152 -0) </details> ### 📄 Description Serve workflows as web services with HTTP endpoints, real-time event streaming, and support for custom StartEvent objects. WorkflowServer: - exposes HTTP endpoints for workflow execution, based on Starlette - can be integrated in existing ASGI applications (e.g. FastAPI) or run standalone using uvicorn under the hood - supports both synchronous (/workflows/{name}/run) and asynchronous (/workflows/{name}/run-nowait) execution Event Streaming: - /events/{handler_id} endpoint for streaming workflow events in real-time - supports both NDJSON and Server-Sent Events (SSE) formats Custom StartEvent Support: - Accepts custom `StartEvent` objects via `start_event` parameter containing the serialized event instance Dependencies Added: - starlette>=0.39.0 - uvicorn>=0.32.0 - httpx>=0.25.0 for the testing client (dev dependency) ## API Endpoints | Method | Endpoint | Description | |--------|------------------------------|-------------------------------------| | GET | /health | Health check | | GET | /workflows | List available workflows | | POST | /workflows/{name}/run | Execute workflow synchronously | | POST | /workflows/{name}/run-nowait | Execute workflow asynchronously | | GET | /results/{handler_id} | Get async workflow result | | GET | /events/{handler_id} | Stream workflow events (NDJSON/SSE) | ## Example Usage ```py # Server setup server = WorkflowServer() server.add_workflow("greeting", GreetingWorkflow()) await server.serve(host="0.0.0.0", port=8000) # Client usage with custom StartEvent curl -X POST http://localhost:8000/workflows/greeting/run \ -H "Content-Type: application/json" \ -d '{"start_event": "{\"__is_pydantic\": true, \"value\": {\"_data\": {\"name\": \"Alice\"}}, \"qualified_name\": \"workflows.events.StartEvent\"}"}' # Event streaming curl http://localhost:8000/events/{handler_id}?sse=true ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-16 02:16:25 -05:00
yindo closed this issue 2026-02-16 02:16:25 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: run-llama/workflows-py#59