Skip to content

Conversation

Copy link

Copilot AI commented Sep 29, 2025

This PR converts the existing .NET 8 Azure Functions Timer sample to Python v2 with 100% functional equivalence, as requested in the issue.

Overview

The conversion maintains all key functionality while adopting the Python v2 programming model with decorators for a more intuitive and Pythonic development experience.

Key Changes

Function Implementation

  • Converted C# timer function to Python v2: Replaced timerFunction.cs with timer_function.py using the @app.timer_trigger decorator
  • Preserved timer schedule configuration: Uses the same %TIMER_SCHEDULE% environment variable with NCRONTAB format
  • Maintained development features: run_on_startup=True equivalent to the original RunOnStartup=true for immediate execution during testing
  • Past due detection: Implemented mytimer.past_due equivalent to myTimer.IsPastDue for handling delayed executions

Runtime and Infrastructure

  • Updated Azure runtime: Changed from 'dotnet-isolated' to 'python' with version '3.11' in Bicep configuration
  • Azure Developer CLI: Modified azure.yaml to specify Python language and updated project metadata
  • Function host configuration: Enhanced host.json with Python-specific settings and extension bundles

Development Environment

  • Python tooling: Updated .devcontainer configuration with Python extensions and Python 3.11 support
  • Dependencies: Created minimal requirements.txt with azure-functions>=1.18.0
  • Local development: Updated local.settings.json to use Python runtime

Documentation and Examples

  • README updates: Replaced C# code examples with Python equivalents throughout the documentation
  • Function reference: Updated code snippets to demonstrate Python v2 programming model patterns
  • Key features documentation: Maintained explanations of all original functionality with Python-specific details

Code Quality

  • Modern Python practices: Used datetime.datetime.now(datetime.timezone.utc) instead of deprecated utcnow() for Python 3.12+ compatibility
  • Security validation: 0 CodeQL alerts and 0 dependency vulnerabilities
  • Syntax validation: All Python code validated and compiles correctly

Functional Equivalence Maintained

The Python version preserves all original functionality:

@app.timer_trigger(schedule="%TIMER_SCHEDULE%", 
                   arg_name="mytimer", 
                   run_on_startup=True,
                   use_monitor=False) 
def timer_function(mytimer: func.TimerRequest) -> None:
    utc_timestamp = datetime.datetime.now(datetime.timezone.utc).isoformat()
    logging.info(f'Python timer trigger function executed at: {utc_timestamp}')
    
    if mytimer.past_due:
        logging.warning('The timer is running late!')
  • Timer trigger with configurable schedule via environment variable
  • Immediate execution on startup for development/testing
  • Past due detection and appropriate logging
  • Application Insights integration through host.json
  • Same deployment process with azd up
  • Managed identity authentication preserved in infrastructure

Deployment

The converted function maintains the same deployment patterns:

  • Uses identical infrastructure (App Service Plan, Storage, Application Insights, VNet)
  • Supports the same azd up deployment workflow
  • Maintains VNet configuration options (VNET_ENABLED environment variable)
  • Preserves managed identity security model

This conversion provides a direct Python equivalent of the .NET timer function sample while following Azure Functions Python v2 best practices.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cdn.functions.azure.com
    • Triggering command: func start --build-native-deps --verbose (dns block)
  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)
  • https://api.github.com/repos/Azure-Samples/Azure-Samples%2Ffunctions-quickstart-dotnet-azd-timer/languages
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Convert to python</issue_title>
<issue_description>This is the base template written in .NET 8. Please convert this in a new branch for Python. I want 100% functional equivalence and documentation, however it should be in the style of Python v2. See this HTTP Python sample as a reference for ideal style, and this reference documentation for Python v2. </issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #9

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits September 29, 2025 17:58
Co-authored-by: paulyuk <1968137+paulyuk@users.noreply.github.com>
Co-authored-by: paulyuk <1968137+paulyuk@users.noreply.github.com>
Copilot AI changed the title [WIP] Convert to python Convert .NET Timer Function to Python v2 Programming Model Sep 29, 2025
Copilot finished work on behalf of paulyuk September 29, 2025 18:03
@im-samz
Copy link
Contributor

im-samz commented Nov 3, 2025

Took the content and put it into this sample: https://github.com/Azure-Samples/functions-quickstart-python-azd-timer

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.

Convert to python

3 participants