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.

Why Use It

Documenting Azure Functions HTTP APIs typically requires maintaining a separate OpenAPI spec by hand. azure-functions-openapi generates the spec automatically from decorated handlers, keeping documentation and code in sync.

Scope

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

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

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.decorator import openapi
from azure_functions_openapi.openapi import get_openapi_json, get_openapi_yaml
from azure_functions_openapi.swagger_ui import 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 get_openapi_json(
        title="Sample API",
        description="OpenAPI document for the Sample API.",
    )


@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 get_openapi_yaml(
        title="Sample API",
        description="OpenAPI document for the Sample API.",
    )


@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

Demo

The representative hello 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

Documentation

Ecosystem

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.14.0.tar.gz (373.5 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.14.0-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for azure_functions_openapi-0.14.0.tar.gz
Algorithm Hash digest
SHA256 afa8b244a33ec9b07d90bc45d5c7955b0582a7fb680e1b1caf77def37c12c916
MD5 251152e0a2dba016f70bf58e15a31720
BLAKE2b-256 9594c2ad75f10eb013089c61613b0cd7f95283fbb35f8d058ada085e6f598a1f

See more details on using hashes here.

Provenance

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

Publisher: release.yml on yeongseon/azure-functions-openapi

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.14.0-py3-none-any.whl.

File metadata

File hashes

Hashes for azure_functions_openapi-0.14.0-py3-none-any.whl
Algorithm Hash digest
SHA256 efba9332e3dd663eb5bd14c64316f1b5aa2a0c498b63d1d39a162d74f80a84b9
MD5 b250feda0ee57ec49a815506d35a2e56
BLAKE2b-256 d94bdf038438f30b3d8100ac1ce7a505357b7bcd38b1a121b3744784f141736e

See more details on using hashes here.

Provenance

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

Publisher: release.yml on yeongseon/azure-functions-openapi

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