Skip to main content

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

Project description

azure-functions-openapi

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

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

Scope

  • Azure Functions Python v2 programming model
  • Decorator-based func.FunctionApp() applications
  • HTTP-triggered functions documented with @openapi
  • Optional 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 generation and validation workflows

Demo

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

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",
    request_model={"name": "string"},
    response_model={"message": "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

Documentation

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.12.0.tar.gz (336.3 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.12.0-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: azure_functions_openapi-0.12.0.tar.gz
  • Upload date:
  • Size: 336.3 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.12.0.tar.gz
Algorithm Hash digest
SHA256 7efa6f87b7e2c0fe47bf33d8c0c62a3ff5977494e622a0a29c7d187d1a85ae86
MD5 318ee184c9fe12709f1334d0795f0274
BLAKE2b-256 f5e4ac8fe562d9dfd568cd05100ffd5098dd00533a143c3f32d3c922f026d01e

See more details on using hashes here.

Provenance

The following attestation bundles were made for azure_functions_openapi-0.12.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.12.0-py3-none-any.whl.

File metadata

File hashes

Hashes for azure_functions_openapi-0.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ae0ca96f86ea54bbd55f4f729485b4780a263280cbf6a4a8e02405543b7e01a5
MD5 6f6f211ec3f7181c7744fc430186a0a2
BLAKE2b-256 ccd1efd8ccdb98d8299e85f5077bd5c3ceba6604788c7dfa16285b952f2727ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for azure_functions_openapi-0.12.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