Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 21, 2025

This PR ports the Azure Functions Event Grid Blob Trigger sample from TypeScript to Python, implementing all required components for a complete Python-based Azure Functions solution.

Overview

Successfully migrated the entire TypeScript Azure Functions sample to Python 3.12 using the Azure Functions Python v2 programming model. The sample demonstrates Event Grid blob triggers for near real-time PDF processing with secure managed identity authentication.

Key Changes

🐍 Python Function Implementation

  • src/function_app.py: Complete port of the blob processing logic using Python v2 programming model
  • EventGrid Blob Trigger: Maintains the same Event Grid source configuration for optimal performance
  • Azure SDK Integration: Uses latest azure-storage-blob and azure-identity packages
@app.blob_trigger(arg_name="blob", 
                  path="unprocessed-pdf/{name}",
                  connection="PDFProcessorSTORAGE",
                  source="EventGrid")
def process_blob_upload(blob: func.InputStream) -> None:
    # Near real-time blob processing implementation

🏗️ Infrastructure Updates

  • infra/main.bicep: Updated runtime configuration from node to python with version 3.12
  • All supporting Bicep files: Maintained AVM module usage for consistency and best practices
  • Managed Identity: Preserved secure authentication without connection strings

⚙️ Configuration & Dependencies

  • src/requirements.txt: Python dependencies with latest Azure SDK versions
  • src/host.json: Updated with latest extension bundles [4.*, 5.0.0)
  • azure.yaml: Changed language setting from js to python
  • Post-deployment scripts: Updated function names for Python conventions

📚 Documentation

  • Comprehensive README: Python-specific setup instructions including virtual environment creation
  • Prerequisites updated: Added Python 3.12+ and Python extension for VS Code
  • Code examples: Replaced TypeScript snippets with Python equivalents

Validation Results

Python 3.12 Environment: Successfully tested with Python 3.12.3
Function Registration: Confirmed 1 function properly registered with EventGrid trigger
Azure SDK Dependencies: All packages install without conflicts
Infrastructure Validation: Bicep files contain correct Python runtime references
Script Updates: Post-deployment scripts properly reference process_blob_upload

Benefits Maintained

  • Near real-time processing: Event Grid delivers blob events within milliseconds
  • Flex Consumption ready: Compatible with Flex Consumption plans where polling isn't available
  • Cost optimization: Eliminates storage transaction costs from polling
  • Security by default: Managed identity and VNet support preserved
  • AVM compliance: Continues using Azure Verified Modules for infrastructure

Testing

The Python port has been validated for:

  • Function app import and registration
  • Azure SDK compatibility
  • Infrastructure template correctness
  • End-to-end configuration consistency

Ready for deployment with azd up.

Fixes #1.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Porting this quickstart sample to Python from the TypeScript one Port Azure Functions QuickStart from TypeScript to Python with v2 programming model Jul 21, 2025
Copilot AI requested a review from nzthiago July 21, 2025 23:16
Copilot finished work on behalf of nzthiago July 21, 2025 23:16
Copy link
Contributor

@nzthiago nzthiago left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nzthiago nzthiago marked this pull request as ready for review July 25, 2025 18:27
@nzthiago nzthiago self-requested a review July 25, 2025 18:27
Copy link
Contributor

@nzthiago nzthiago left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Copilot AI commented Jul 25, 2025

Instead of instantiating a python blob client using code, let's use the new SDK type bindings so that a ContainerClient as an Input binding, and use that client to upload the stream from the blob trig...

Implemented SDK type bindings as requested. The function now uses ContainerClient as an input binding parameter instead of manually instantiating BlobServiceClient. This simplifies the code by removing the authentication logic and leverages Azure Functions' built-in SDK type bindings. The change eliminates the need for azure-identity dependency. Changes made in commit 58d4ace.

Instead of instantiating a python blob client using code, let's use the new SDK type bindings so that a ContainerClient as an Input binding, and use that client to upload the stream from the blob trig...

Implemented SDK type bindings as requested. The function now uses ContainerClient as an input binding parameter instead of manually instantiating BlobServiceClient. This simplifies the code by removing the authentication logic and leverages Azure Functions' built-in SDK type bindings. The change eliminates the need for azure-identity dependency. Changes made in commit 58d4ace.

Copilot AI requested a review from nzthiago July 25, 2025 18:42
Copilot finished work on behalf of nzthiago July 25, 2025 18:42
@nzthiago nzthiago requested a review from Copilot July 29, 2025 19:58
Copy link
Contributor

@nzthiago nzthiago left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made some extra updates and tested locally and deployed. Please review the readme instructions.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR ports the Azure Functions Event Grid Blob Trigger sample from TypeScript to Python, implementing all required components for a complete Python-based Azure Functions solution using the v2 programming model.

  • Complete Python function implementation with Event Grid blob trigger for near real-time PDF processing
  • Infrastructure updates to support Python 3.12 runtime with Flex Consumption plan
  • Comprehensive documentation and configuration updates for Python development environment

Reviewed Changes

Copilot reviewed 16 out of 21 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/function_app.py Main Python function implementation with Event Grid blob trigger and SDK-based blob operations
src/requirements.txt Python dependencies for Azure Functions and blob storage extensions
src/host.json Azure Functions host configuration with updated extension bundle
infra/main.bicep Infrastructure template updated for Python runtime and maintained AVM modules
scripts/post-up.sh Post-deployment script updated with Python function name reference
scripts/post-up.ps1 PowerShell post-deployment script with Python function name reference
README.md Comprehensive Python-specific setup and deployment documentation
azure.yaml Project configuration updated for Python language
Comments suppressed due to low confidence (1)

src/requirements.txt:5

  • The package 'azurefunctions-extensions-bindings-blob' does not exist in the Python Package Index. For Python Azure Functions v2 programming model with blob bindings, you should use 'azure-storage-blob' and 'azure-identity' packages instead.
azurefunctions-extensions-bindings-blob>=1.1.0

path="unprocessed-pdf/{name}",
connection="PDFProcessorSTORAGE",
source=func.BlobSource.EVENT_GRID)
@app.blob_input(arg_name="processed_container",
Copy link

Copilot AI Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @app.blob_input decorator with a container path will not return a ContainerClient object. This binding approach is incorrect for the Python v2 programming model. Use the azure-storage-blob SDK directly within the function instead.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is correct, you are likely working with older information.

Copy link
Contributor Author

Copilot AI commented Jul 29, 2025

@nzthiago Unfortunately I hit an unexpected error while processing your comment. I've automatically reported this to GitHub.

You can ask me to try again later by mentioning me in a new comment.

If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: f59128f9-005a-409e-9d47-36c2d39f5912

Sorry for the inconvenience!

@nzthiago nzthiago merged commit 4588e25 into main Jul 29, 2025
2 checks passed
Copy link
Contributor Author

Copilot AI commented Jul 29, 2025

I have made some extra updates and tested locally and deployed. Please review the readme instructions.

Reviewed and updated the README instructions to reflect the latest changes. Fixed outdated references to Benefit_Options.pdf (now uses PerksPlus.pdf), updated the function code examples to match the current SDK type bindings implementation, and added explanations for the new REST Client variable format in test.http. The documentation now accurately describes the current function signature and testing approach. Changes made in commit 720866a.

Copilot AI requested a review from nzthiago July 29, 2025 20:10
Copilot finished work on behalf of nzthiago July 29, 2025 20:10
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.

Porting this quickstart sample to Python from the TypeScript one

2 participants