Skip to main content

OpenAPI (Swagger) integration for Azure Functions Python v2 programming model

Project description

Azure Functions OpenAPI

PyPI Python Version CI Release Security Scans codecov pre-commit Docs License: MIT

Read this in: 한국어 | 日本語 | 简体中文

OpenAPI (Swagger) documentation and Swagger UI for the Azure Functions Python v2 programming model.


Part of the Azure Functions Python DX Toolkit → Bring FastAPI-like developer experience to Azure Functions

Why this exists

Azure Functions Python v2 has no built-in API documentation story:

  • No auto-generated docs — you maintain OpenAPI specs by hand or not at all
  • No Swagger UI — no browser-based API explorer for testing endpoints
  • Hard to test — consumers rely on tribal knowledge or external tools to discover your API
  • Spec drift — hand-written docs diverge from actual handler behavior over time

Before / After

❌ Without azure-functions-openapi — maintain specs by hand

# openapi_spec.json — manually written, manually updated
{
    "paths": {
        "/api/users": {
            "post": {
                "summary": "Create user",
                "requestBody": { "...": "..." },
                "responses": { "200": { "...": "..." } }
            }
        }
    }
}

# function_app.py — no connection to the spec above
@app.route(route="users", methods=["POST"])
def create_user(req):
    ...

Spec drifts. Consumers guess. No Swagger UI.

✅ With azure-functions-openapi — spec lives next to the handler

@app.route(route="users", methods=["POST"])
@openapi(
    summary="Create user",
    request_body={"type": "object", "properties": {"name": {"type": "string"}}},
    response={200: {"description": "User created"}},
)
def create_user(req):
    ...

# Auto-generated endpoints:
# GET /api/openapi.json  — always in sync
# GET /api/docs          — Swagger UI included

Spec matches code. Always. Swagger UI out of the box.

What it does

  • @openapi decorator — attach operation metadata directly to your handler
  • Auto-generated spec/openapi.json and /openapi.yaml endpoints from decorated handlers
  • Swagger UI — built-in /docs endpoint with security defaults
  • CLI tooling — generate specs at build time for CI validation

FastAPI comparison

Feature FastAPI azure-functions-openapi
API docs generation Built-in from type hints @openapi decorator on handlers
Swagger UI /docs auto-served render_swagger_ui() endpoint
OpenAPI spec Auto-generated /openapi.json get_openapi_json() endpoint
CLI spec export N/A azure-functions-openapi generate
Pydantic integration Native request_model= / response_model=

Scope

  • Azure Functions Python v2 programming model
  • Decorator-based func.FunctionApp() applications
  • HTTP-triggered functions documented with @openapi
  • Pydantic schema generation (requires Pydantic v2)

This package does not support the legacy function.json-based v1 programming model.

What this package does not do

This package does not own:

Features

  • @openapi decorator for operation metadata
  • /openapi.json, /openapi.yaml, and /docs endpoints
  • Query, path, header, body, and response schema support
  • Swagger UI helper with security defaults
  • CLI tooling for spec generation (JSON and YAML output)

CLI Quick Start

Generate an OpenAPI spec from your decorated function app:

# Install
pip install azure-functions-openapi

# Generate spec from a function app module (registers @openapi routes)
azure-functions-openapi generate --app function_app --title "My API" --format json

# Write to file with pretty-printing
azure-functions-openapi generate --app function_app --title "My API" --pretty --output openapi.json

# YAML output
azure-functions-openapi generate --app function_app --format yaml --output openapi.yaml

Pass module:variable when the FunctionApp instance has a non-default name:

azure-functions-openapi generate --app function_app:my_app --title "My API"

See the CLI Guide for all options and CI integration examples.

Installation

pip install azure-functions-openapi

Your Function App dependencies should include:

azure-functions
azure-functions-openapi

Quick Start

import json

import azure.functions as func

from azure_functions_openapi import (
    get_openapi_json,
    get_openapi_yaml,
    openapi,
    render_swagger_ui,
)


app = func.FunctionApp()


@app.function_name(name="http_trigger")
@app.route(route="http_trigger", auth_level=func.AuthLevel.ANONYMOUS, methods=["POST"])
@openapi(
    summary="Greet user",
    route="/api/http_trigger",
    method="post",
    request_body={
        "type": "object",
        "properties": {"name": {"type": "string"}},
        "required": ["name"],
    },
    response={
        200: {
            "description": "Successful greeting",
            "content": {
                "application/json": {
                    "schema": {
                        "type": "object",
                        "properties": {"message": {"type": "string"}},
                    }
                }
            },
        }
    },
    tags=["Example"],
)
def http_trigger(req: func.HttpRequest) -> func.HttpResponse:
    data = req.get_json()
    name = data.get("name", "world")
    return func.HttpResponse(
        json.dumps({"message": f"Hello, {name}!"}),
        mimetype="application/json",
    )


@app.function_name(name="openapi_json")
@app.route(route="openapi.json", auth_level=func.AuthLevel.ANONYMOUS, methods=["GET"])
def openapi_json(req: func.HttpRequest) -> func.HttpResponse:
    return func.HttpResponse(
        get_openapi_json(
            title="Sample API",
            description="OpenAPI document for the Sample API.",
        ),
        mimetype="application/json",
    )


@app.function_name(name="openapi_yaml")
@app.route(route="openapi.yaml", auth_level=func.AuthLevel.ANONYMOUS, methods=["GET"])
def openapi_yaml(req: func.HttpRequest) -> func.HttpResponse:
    return func.HttpResponse(
        get_openapi_yaml(
            title="Sample API",
            description="OpenAPI document for the Sample API.",
        ),
        mimetype="application/x-yaml",
    )


@app.function_name(name="swagger_ui")
@app.route(route="docs", auth_level=func.AuthLevel.ANONYMOUS, methods=["GET"])
def swagger_ui(req: func.HttpRequest) -> func.HttpResponse:
    return render_swagger_ui()

Run locally with Azure Functions Core Tools:

func start

Verify locally and on Azure

After deploying (see docs/deployment.md), the same request produces the same response in both environments.

Local

curl -s http://localhost:7071/api/http_trigger \
  -H "Content-Type: application/json" \
  -d '{"name": "World"}'
{"message": "Hello, World!"}

Azure

curl -s "https://<your-app>.azurewebsites.net/api/http_trigger" \
  -H "Content-Type: application/json" \
  -d '{"name": "World"}'
{"message": "Hello, World!"}

The /api/openapi.json, /api/openapi.yaml, and /api/docs endpoints are also available in both environments.

Verified against a temporary Azure Functions deployment in koreacentral (Python 3.12, Consumption plan). Response captured and URL anonymized.

Demo

The representative webhook_receiver example shows the full outcome of adopting this library:

  • You annotate an Azure Functions v2 HTTP handler with @openapi.
  • The package generates a real OpenAPI document for that route.
  • The same route is rendered in Swagger UI for browser-based inspection.

Generated Spec Result

The generated OpenAPI file is captured as a static preview from the same example run, so the README shows the actual document produced by the representative function.

OpenAPI spec preview

Swagger UI Result

The web preview below is generated from the same representative example and captured automatically from the rendered Swagger UI page produced by that example flow.

OpenAPI Swagger UI preview

When to use

  • You have HTTP-triggered Azure Functions and need API documentation
  • You want Swagger UI for browser-based API testing
  • You need OpenAPI specs for client code generation or CI validation
  • You want to keep docs in sync with handler code automatically

Documentation

Ecosystem

This package is part of the Azure Functions Python DX Toolkit.

Design principle: azure-functions-openapi owns API documentation and spec generation. azure-functions-validation owns request/response validation and serialization. azure-functions-langgraph owns LangGraph runtime exposure.

Package Role
azure-functions-openapi OpenAPI spec generation and Swagger UI
azure-functions-validation Request/response validation and serialization
azure-functions-db Database bindings for SQL, PostgreSQL, MySQL, SQLite, and Cosmos DB
azure-functions-langgraph LangGraph deployment adapter for Azure Functions
azure-functions-scaffold Project scaffolding CLI
azure-functions-logging Structured logging and observability
azure-functions-doctor Pre-deploy diagnostic CLI
azure-functions-durable-graph Manifest-first graph runtime with Durable Functions (experimental)
azure-functions-python-cookbook Recipes and examples

For AI Coding Assistants

This repository includes llms.txt and llms-full.txt in the root directory. These files provide comprehensive package and API information optimized for LLM context windows.

  • llms.txt — Quick reference with core API, installation, and quick-start example
  • llms-full.txt — Complete reference with full signatures, patterns, design principles, and ecosystem context

Use these files to get better context when working with this package in AI-assisted coding environments.

Disclaimer

This project is an independent community project and is not affiliated with, endorsed by, or maintained by Microsoft.

Azure and Azure Functions are trademarks of Microsoft Corporation.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

azure_functions_openapi-0.18.0.tar.gz (426.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

azure_functions_openapi-0.18.0-py3-none-any.whl (30.6 kB view details)

Uploaded Python 3

File details

Details for the file azure_functions_openapi-0.18.0.tar.gz.

File metadata

  • Download URL: azure_functions_openapi-0.18.0.tar.gz
  • Upload date:
  • Size: 426.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for azure_functions_openapi-0.18.0.tar.gz
Algorithm Hash digest
SHA256 6f3cdb426b60a0ba2a96b48d037b2f67fd65a2c4b1d72de1c31f6f7c69214296
MD5 cec951e89884f1ebc345e8a05101331e
BLAKE2b-256 62fd65c7d7f30138685c5a277fa161c5fb70704d44b8ed707ef32046c2e4f5f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for azure_functions_openapi-0.18.0.tar.gz:

Publisher: publish-pypi.yml on yeongseon/azure-functions-openapi-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file azure_functions_openapi-0.18.0-py3-none-any.whl.

File metadata

File hashes

Hashes for azure_functions_openapi-0.18.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9b52bf855188adc659630230ec1f117f0281ceb56566393dac2b7469514ca5e2
MD5 8689648024fe673876d225d39dfa857a
BLAKE2b-256 65de6b08ff3e92fd57fa422380cd0fd3b78d0e0b5c3663ff483af6a197fcc38c

See more details on using hashes here.

Provenance

The following attestation bundles were made for azure_functions_openapi-0.18.0-py3-none-any.whl:

Publisher: publish-pypi.yml on yeongseon/azure-functions-openapi-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page