MetaEngine.Python.OpenApi.FastApi

Generate Python models and FastAPI-ready services from OpenAPI/Swagger specifications. Perfect for API-first development with async/await, httpx client, and full type hints.

npm versionnpm downloadslicensenuget version
NPM Package

Use as a CLI tool via npm/npx

# Install globally
npm install -g @metaengine/openapi-python
# Or use with npx
npx @metaengine/openapi-python api.yaml ./src/api

Requirements: Node.js 18+, .NET 8.0+ runtime

NuGet Package

Use programmatically in .NET projects

# Install via dotnet CLI
dotnet add package MetaEngine.Python.OpenApi.FastApi

Requirements: .NET Standard 2.0+

Command Line Usage

Basic Syntax
npx @metaengine/openapi-python <input> <output> [options]

Supports OpenAPI 3.0+ specifications in both JSON and YAML formats.

Quick Examples
# Generate from local file
npx @metaengine/openapi-python api.yaml ./generated
# Generate from URL
npx @metaengine/openapi-python https://api.example.com/openapi.json ./generated
# With Pydantic models and documentation
npx @metaengine/openapi-python api.yaml ./generated \
--pydantic-models \
--documentation \
--camel-case-aliases
CLI Options
OptionDescription
--include-tags <tags>Filter by OpenAPI tags (comma-separated, case-insensitive)
--service-suffix <suffix>Service naming suffix [default: Service]
--options-threshold <n>Parameter count for options object [default: 4]
--documentationGenerate docstring comments
--pydantic-modelsEnable Pydantic v2 models for validation (opt-in)
--camel-case-aliasesGenerate camelCase field aliases for Pydantic models
--strict-validationEnable strict OpenAPI validation
--verboseEnable verbose logging
--help, -hShow help message

Programmatic Usage (C#)

Configuration Example
Configuration Example

FastAPI Support

Generates code compatible with FastAPI framework. Optional Pydantic models for automatic validation and serialization.

async/await

Native async support with httpx AsyncClient for high-performance non-blocking I/O operations.

Type Hints

Full type hint coverage with Python 3.12+ syntax including list[T], dict[K,V], and Optional[T].

Options Reference

Python Options

  • UsePydanticModels()Enable Pydantic v2 models for validation (default: false)
  • GenerateCamelCaseAliases()Generate camelCase field aliases for Pydantic models
  • WithServiceSuffix(string)Service suffix (default: "Service")
  • WithDocumentation()Enable docstring comments
  • WithOptionsObjectThreshold(int)Parameter count for options object (default: 4)

OpenAPI Filtering

  • WithStrictValidation()Enable strict OpenAPI validation
  • WithOperationFilter(Func)Filter operations by predicate
  • WithHeaderFilter(Func)Filter header parameters

Naming Transformations

  • Types(Func)Transform type names
  • Paths(Func)Transform output paths
  • FileNames(Func)Transform file names

File Management

  • CleanDestination()Clean output directory before generation
  • AlwaysOverwrite()Always overwrite existing files
  • OnlyWhenModelChanged()Update only when model changes
  • OnlyWhenNew()Write only new files, preserve existing
  • CleanDirectories(...)Clean specific subdirectories

Diagnostics

  • EnableVerboseLogging()Enable detailed logging