Update the Python example to use the OpenFaaS python-sdk#8
Conversation
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>
AI Pull Request OverviewSummary
Approval rating (1-10)9 Summary per file
Overall AssessmentThe 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 ReviewDetailed Reviewpython-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. |
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):faas-cli --shrinkwrap, hand-rolled tar creation, manual HMAC signing and HTTP request) with theopenfaas_sdk.builderpackageFunctionBuilder.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-clibeing 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-worldnode20 handler and pushing tottl.sh.