Skip to content

Update the Python example to use the OpenFaaS python-sdk#8

Open
welteki wants to merge 2 commits into
openfaas:masterfrom
welteki:python-sdk
Open

Update the Python example to use the OpenFaaS python-sdk#8
welteki wants to merge 2 commits into
openfaas:masterfrom
welteki:python-sdk

Conversation

@welteki
Copy link
Copy Markdown
Member

@welteki welteki commented Apr 28, 2026

Description

Updates the Python example to use the official OpenFaaS python-sdk, mirroring the approach already used in the Go example.

Python (python-request/build.py):

  • Replaces the manual implementation (subprocess call to faas-cli --shrinkwrap, hand-rolled tar creation, manual HMAC signing and HTTP request) with the openfaas_sdk.builder package
  • Build logs are now streamed as they arrive using FunctionBuilder.build_stream()

Additionally, the Go example is updated to stream build output using BuildWithStream() and bumps the go-sdk to v0.3.0.

Motivation and context

The Go example was previously updated to use the go-sdk. This brings the Python example to the same standard — removing the dependency on faas-cli being present on PATH and eliminating hand-rolled plumbing that is now provided by the official SDK. Streaming build output improves the user experience for both examples.

How has this been tested

Both examples were tested end-to-end against a live Function Builder, building the hello-world node20 handler and pushing to ttl.sh.

welteki added 2 commits April 28, 2026 11:33
Replace the manual implementation (faas-cli shrinkwrap subprocess, hand-rolled
tar creation, and manual HMAC signing) with the official OpenFaaS python-sdk.
Build logs are streamed as they arrive using build_stream(). Adds --name,
--platforms, and --build-args flags to match the go-sdk example.

Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
Switch from Build() to BuildWithStream() so build logs are printed as they
arrive. Bumps go-sdk to v0.2.18 which introduced BuildWithStream.

Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
@reviewfn
Copy link
Copy Markdown

reviewfn Bot commented Apr 28, 2026

AI Pull Request Overview

Summary

  • Migrated Python example from manual subprocess/tar/HMAC implementation to official openfaas-sdk
  • Added --name, --platforms, and --build-args flags to Python script for feature parity with Go
  • Implemented streaming build logs in both Python and Go examples for improved UX
  • Bumped Go SDK to v0.3.0 and switched to BuildWithStream API
  • Added requirements.txt to pin Python SDK dependency
  • Updated README with new installation and usage instructions

Approval rating (1-10)

9

Summary per file

File path Summary
README.md Updated Python and Go sections with new SDK usage
go-request/main.go Switched to BuildWithStream for log streaming
go.mod Bumped go-sdk to v0.3.0
go.sum Updated dependency hashes
python-request/build.py Migrated to SDK with new flags and streaming
python-request/requirements.txt Added SDK dependency pin

Overall Assessment

The PR effectively modernizes the examples by replacing manual implementations with official SDKs, adding streaming capabilities, and ensuring consistency between Python and Go. Changes are well-tested and improve maintainability.

Detailed Review

Detailed Review

python-request/build.py: The migration to openfaas-sdk simplifies the code significantly. Streaming implementation looks correct. However, argument parsing for --platforms and --build-args does not trim whitespace from comma-separated values, which could cause issues if inputs contain spaces (e.g., "linux/amd64, linux/arm64" results in platforms array with leading space). Consider adding .strip() to each split element.

go-request/main.go: Clean transition to BuildWithStream API with proper error handling in the results loop. Parsing logic has the same whitespace trimming issue as Python - strings.Split on platforms and build args doesn't handle spaces around commas, potentially leading to invalid platform strings or build arg keys/values.

python-request/requirements.txt: Pinning to git+https without a specific tag or commit hash could lead to instability if the repository changes. Consider using a version tag if available from the python-sdk releases.

README.md: Updates accurately reflect the new SDK usage and requirements. Installation instructions are clear.

go.mod/go.sum: Version bump to v0.3.0 is appropriate for the new streaming API.

No security issues identified. Error handling is adequate for example code. The changes reduce external dependencies (removing faas-cli requirement) and improve user experience with streaming logs.

AI agent details.

Agent processing time: 1m39.783s
Environment preparation time: 3.753s
Total time from webhook: 1m45.806s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant