Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
a973faa to
64a9399
Compare
This comment has been minimized.
This comment has been minimized.
64a9399 to
9024d4b
Compare
This comment has been minimized.
This comment has been minimized.
9024d4b to
44ee83a
Compare
This comment has been minimized.
This comment has been minimized.
44ee83a to
9601a3e
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
9601a3e to
9eadd02
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
9eadd02 to
a355608
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Add step-by-step examples for common patterns: boto3 S3, Kafka producer, OpenAI Chat API, SSE streaming, streaming OpenAI responses, ECR with IRSA, OpenFaaS REST API, and Playwright web testing. Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
a355608 to
97ac775
Compare
AI Pull Request OverviewSummary
Approval rating (1-10)6 - Strong documentation value but critical API usage errors in OpenAI examples prevent approval without fixes. Summary per fileSummary per file
Overall AssessmentThis PR significantly enhances the OpenFaaS documentation by providing practical, end-to-end examples for common serverless integration patterns. The examples follow consistent structure and demonstrate proper security practices with OpenFaaS secrets. However, the OpenAI examples contain critical API usage errors that would prevent them from working, requiring immediate correction before merge. Detailed ReviewDetailed Reviewdocs/languages/python/examples/ecr-irsa.md
docs/languages/python/examples/kafka.md
docs/languages/python/examples/openai.mdCRITICAL: Incorrect API usage - these examples will not work
docs/languages/python/examples/openfaas-api.md
docs/languages/python/examples/playwright.md
docs/languages/python/examples/s3-boto3.md
docs/languages/python/examples/sse.md
docs/languages/python/index.md
mkdocs.yml
AI agent details. |
AI Pull Request OverviewSummary
Approval rating (1-10)9 — High-quality, production-ready examples with proper security practices. Minor issues: missing error handling in some examples, hardcoded values, and one potential race condition in the ECR example. Summary per fileSummary per file
Overall AssessmentThis is a solid documentation PR that fills a significant gap in the Python examples. The examples are practical, tested, and follow OpenFaaS best practices (secrets management, client reuse, proper templating). The code examples are idiomatic Python and demonstrate advanced patterns like IRSA, SSE streaming, and headless browser automation. The examples are comprehensive and well-structured with step-by-step walkthroughs. However, there are a few code quality issues that should be addressed: missing error handling in several examples, a potential race condition in the ECR example, and some hardcoded values that could be configurable. Detailed ReviewDetailed ReviewCritical Issues1. Race condition in ECR exampleFile: try:
ecrClient.describe_repositories(repositoryNames=[name])
return {
"statusCode": 200,
"body": json.dumps({"message": "Repository already exists"})
}
except ecrClient.exceptions.RepositoryNotFoundException:
passIssue: This check-then-act pattern has a race condition. Between the Fix: Wrap try:
response = ecrClient.create_repository(...)
return {"statusCode": 201, "body": json.dumps({...})}
except ecrClient.exceptions.RepositoryAlreadyExistsException:
return {"statusCode": 200, "body": json.dumps({"message": "Repository already exists"})}
except Exception as e:
return {"statusCode": 500, "body": f"Failed to create repository: {str(e)}"}2. Missing error handling in OpenFaaS API exampleFile: Issue: The Fix: Add try-except blocks: try:
namespaces = requests.get(
f"{gateway}/system/namespaces",
auth=auth,
timeout=10
).json()
except requests.RequestException as e:
return {"statusCode": 502, "body": f"Failed to list namespaces: {str(e)}"}Medium Issues3. Hardcoded OpenAI model nameFile: Issue: Fix: Use 4. Missing timeout in S3 exampleFile: Issue: The boto3 client has no timeout configuration. S3 operations could hang indefinitely. Fix: Add timeout configuration: import botocore.config
config = botocore.config.Config(
connect_timeout=5,
read_timeout=30,
retries={'max_attempts': 3}
)
return session.client('s3', config=config)5. No validation of required fields in OpenFaaS API exampleFile: Issue: If Fix: Use name = body.get("name")
image = body.get("image")
if not name or not image:
return {"statusCode": 400, "body": "Missing required fields: name and image"}Minor Issues6. Inconsistent secret reading patternFiles: Multiple Observation: Some examples define Recommendation: Use the helper function pattern consistently across all examples for readability. 7. Hardcoded gateway URLFile: Issue: Fix: Document this clearly or provide a local alternative like 8. Missing Content-Type validationFile: Issue: The GET handler lists objects but doesn't validate that the request is actually GET (it only checks for POST later). While the order works, it's clearer to validate the method explicitly. Suggestion: if event.method == 'GET':
# ...
elif event.method == 'POST':
# ...
else:
return {"statusCode": 405, "body": "Method not allowed"}9. Hardcoded region in ECR exampleFile: Issue: 10. Missing validation in SSE exampleFile: Issue: The generator doesn't handle client disconnection. If the client drops the connection, the function continues generating events unnecessarily. Fix: Add a check or document this limitation: def generate():
try:
for i in range(1, 6):
time.sleep(1)
yield f"data: Message {i} of 5\n\n"
except Exception:
pass # Client disconnected
finally:
yield "data: [DONE]\n\n"Positive Notes
Documentation QualityThe markdown is well-formatted with clear use-cases, code blocks, and step-by-step instructions. The examples are comprehensive and include troubleshooting tips (like the SASL mechanism explanations in kafka.md). AI agent details. |

Description
Add detailed, step-by-step examples to the Python language docs.
Examples:
confluent-kafkawith SASL/SSL authentication, including a note on common SASL mechanisms (tested e2e)openaiSDK with secret-based API key management and client reuse (tested e2e)python3-flasktemplate with a FlaskResponsegenerator (tested e2e)boto3with IAM Roles for Service Accounts (IRSA) on EKS for ambient credential discovery, replacing the need for static secrets (tested e2e)Motivation and Context
Make it easier for users to get started with common patterns by providing ready-to-use examples in the official documentation.
How Has This Been Tested?
All examples have been tested end-to-end: functions were built, deployed to a live OpenFaaS cluster, and invoked to verify correct behaviour. SSE streaming was verified to produce chunked responses with the
Accept: text/event-streamheader.Types of changes
Checklist:
git commit -s