{"id":1924,"library":"azure-functions","title":"Azure Functions Python Library","description":"The `azure-functions` Python library provides the core programming model for developing serverless functions on Azure Functions. It enables developers to write event-driven code in Python that scales automatically and runs in response to various triggers (e.g., HTTP requests, timer, queue messages). This library, currently at version 2.0.0, is designed for the Python v2 programming model and is typically used with Azure Functions runtime v4.x. It receives updates in alignment with the Azure Functions platform's development cycle, which often includes features, performance improvements, and security patches.","status":"active","version":"2.0.0","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-functions","tags":["Azure","Serverless","Functions","Cloud","Python","Event-Driven","PaaS"],"install":[{"cmd":"pip install azure-functions","lang":"bash","label":"Install core library"}],"dependencies":[{"reason":"This package is the actual Python language worker that executes Python code within the Azure Functions host. While not a direct `pip` dependency of `azure-functions` itself, it's implicitly required by the Azure Functions runtime to run Python functions.","package":"azure-functions-worker","optional":true},{"reason":"Often found in `requirements.txt` for Python Function Apps, as the Python worker uses gRPC for communication with the Functions host.","package":"grpcio","optional":true},{"reason":"Related to gRPC, sometimes listed in `requirements.txt`.","package":"grpcio-tools","optional":true},{"reason":"Related to gRPC, sometimes listed in `requirements.txt`.","package":"protobuf","optional":true}],"imports":[{"note":"The recommended and standard alias for the Azure Functions library.","symbol":"func","correct":"import azure.functions as func"},{"note":"Initialize the FunctionApp object, the entry point for defining functions in the v2 programming model.","symbol":"FunctionApp","correct":"app = func.FunctionApp()"},{"note":"Type hint for an HTTP request object.","symbol":"HttpRequest","correct":"req: func.HttpRequest"},{"note":"Class for creating an HTTP response object.","symbol":"HttpResponse","correct":"func.HttpResponse(...)"}],"quickstart":{"code":"import azure.functions as func\nimport logging\nimport os\n\n# Instantiate the FunctionApp object\napp = func.FunctionApp()\n\n# Define an HTTP trigger function using a decorator\n@app.route(route=\"http_example\", methods=[\"GET\", \"POST\"])\ndef http_example(req: func.HttpRequest) -> func.HttpResponse:\n    logging.info('Python HTTP trigger function processed a request.')\n\n    # Get name from query parameters or request body\n    name = req.params.get('name')\n    if not name:\n        try:\n            req_body = req.get_json()\n        except ValueError:\n            pass\n        else:\n            name = req_body.get('name')\n\n    if name:\n        return func.HttpResponse(f\"Hello, {name}. This HTTP triggered function executed successfully.\")\n    else:\n        return func.HttpResponse(\n             \"Please pass a name on the query string or in the request body for a personalized response.\",\n             status_code=200\n        )","lang":"python","description":"This quickstart demonstrates a simple HTTP-triggered Azure Function using the Python v2 programming model. It shows how to define a function with the `@app.route` decorator, access request parameters (`HttpRequest`), and return an HTTP response (`HttpResponse`). This code is placed in a `function_app.py` file."},"warnings":[{"fix":"Rewrite function definitions using decorators (`@app.route`, `@app.timer_trigger`, etc.) in a `function_app.py` file or using blueprints. Remove individual `function.json` files. Refer to the official Azure Functions Python v2 programming model documentation for migration guidance.","message":"The Python v2 programming model (used by `azure-functions` 2.0.0+) introduces significant breaking changes from v1. This shifts from using `function.json` files and a strict 'one function per folder' structure to a Python-first, decorator-based approach. Configuration for triggers and bindings is now directly within Python code.","severity":"breaking","affected_versions":"All versions using Python v1 programming model when migrating to v2 programming model."},{"fix":"Migrate your Function Apps to Azure Functions Runtime version 4.x as soon as possible for full support and access to the latest Python versions (3.10, 3.11, 3.12, 3.13 are supported by runtime 4.x). Ensure your Python code is compatible with the v2 programming model.","message":"Azure Functions Runtime versions 2.x and 3.x are End-of-Life (EOL) and no longer supported. While apps on these runtimes may still function, they will not receive new features, security patches, or performance optimizations.","severity":"deprecated","affected_versions":"Azure Functions Runtime 2.x, 3.x"},{"fix":"To mitigate cold starts, consider using a Premium Plan (which keeps instances warm), scheduling periodic 'keep-alive' pings, or keeping your startup code lean by avoiding unnecessary library loads or connections.","message":"Cold starts can significantly impact performance on the Consumption Plan. When a function app goes idle, Azure deallocates resources, leading to a delay (cold start) on the next invocation.","severity":"gotcha","affected_versions":"All versions on Consumption Plan"},{"fix":"For longer execution times, use a Premium or Dedicated Plan. Alternatively, break down long tasks into smaller, parallelizable chunks, or offload heavy work to Durable Functions or other compute services.","message":"Default function timeouts on the Consumption Plan are 5 minutes and cannot be changed. Long-running tasks will be terminated.","severity":"gotcha","affected_versions":"All versions on Consumption Plan"},{"fix":"Reuse client instances where possible. For Python, this often means creating clients outside the function handler (e.g., as global variables or in a singleton pattern) or utilizing connection pooling where available.","message":"Repeatedly instantiating network clients (e.g., `HttpClient`, database connections) within a function's execution path can lead to `Socket Exception` errors due to resource exhaustion and inefficient connection management.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your Azure Function App names are 32 characters or less. Avoid sharing a single storage account across multiple Function Apps if possible.","message":"Function App host names (which derive from the app name) have a maximum length of 32 characters. Longer names can lead to host ID collisions, especially when sharing a storage account, which can impede scaling and lease management.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}