← Back to all products

OpenAPI Spec Generator

$10

Generate OpenAPI 3.0 specifications from Python function signatures and docstrings.

📁 10 files
JSONMarkdownPython

📄 Product Preview

Try the interactive reader and demo tools below, or get the full product with all content unlocked.

📖 Interactive Reader (Free Preview) ⚙ Try Demo Tools 📦 Download Free Sample

📁 File Structure 10 files

openapi-spec-generator/ ├── LICENSE ├── README.md ├── examples/ │ ├── generated_spec.json │ └── sample_api.py ├── free-sample.zip ├── guide/ │ ├── 01_openapi-spec-generator.md │ ├── 02_features.md │ └── 03_quick-start.md ├── index.html └── src/ └── main.py

📖 Documentation Preview README excerpt

OpenAPI Spec Generator

Generate OpenAPI 3.0 specifications from Python function signatures and docstrings. Zero dependencies.

Part of the API Launchpad toolkit by [CodeVault](https://codevault.dev).

Features

  • Function introspection: extracts parameters from type hints and signatures
  • Docstring parsing: Google-style docstrings → parameter descriptions
  • Type mapping: Python types → JSON Schema (str, int, float, bool, list, dict)
  • Module scanning: auto-discover endpoints from function naming conventions
  • Dual output: JSON or YAML (built-in YAML converter, no PyYAML needed)
  • Request body inference: POST/PUT/PATCH functions automatically get request body schemas
  • Zero dependencies — runs on Python stdlib only

Quick Start


# Generate a demo spec
python3 src/main.py --demo

# Generate spec from a Python module
python3 src/main.py --module my_api.py --title "My API" --output spec.json

# Output as YAML
python3 src/main.py --module my_api.py --format yaml --output spec.yaml

Using as a Library


from main import OpenAPIGenerator

gen = OpenAPIGenerator(
    title="Acme Corp API",
    version="2.0.0",
    description="The Acme Corp public API",
    server_url="https://api.example.com/v2",
)

# Register endpoints from your functions
def list_users(limit: int = 10, offset: int = 0) -> list:
    """List all users with pagination.

    Args:
        limit: Maximum number of users to return
        offset: Number of users to skip
    """
    pass

def create_user(name: str, email: str, role: str = "user") -> dict:
    """Create a new user account.

    Args:
        name: User's full name
        email: User's email address
        role: User role (user, admin)
    """
    pass

*... continues with setup instructions, usage examples, and more.*

📄 Code Sample .py preview

src/main.py #!/usr/bin/env python3 """ OpenAPI Spec Generator — Generate OpenAPI 3.0 from Python Functions ==================================================================== Introspects Python function signatures, type hints, and docstrings to automatically generate valid OpenAPI 3.0.3 specifications. Outputs YAML or JSON that can be imported into Swagger UI, Redoc, or Postman. Zero dependencies. Run as CLI or import as module. Part of the API Launchpad toolkit by DataNest. License: MIT """ from __future__ import annotations import inspect import json import logging import re import importlib.util from dataclasses import dataclass, field from pathlib import Path from typing import Any, Callable, get_type_hints # --------------------------------------------------------------------------- # Configuration # --------------------------------------------------------------------------- logging.basicConfig( level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s", datefmt="%Y-%m-%dT%H:%M:%S", ) logger = logging.getLogger("openapi-gen") # Map Python types to JSON Schema types TYPE_MAP: dict[type, dict[str, str]] = { str: {"type": "string"}, int: {"type": "integer"}, float: {"type": "number"}, bool: {"type": "boolean"}, list: {"type": "array", "items": {"type": "string"}}, dict: {"type": "object"}, bytes: {"type": "string", "format": "binary"}, } # --------------------------------------------------------------------------- # ... 498 more lines ...
Buy Now — $10 Back to Products