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 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
| Option | Description |
|---|---|
--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] |
--documentation | Generate docstring comments |
--pydantic-models | Enable Pydantic v2 models for validation (opt-in) |
--camel-case-aliases | Generate camelCase field aliases for Pydantic models |
--strict-validation | Enable strict OpenAPI validation |
--verbose | Enable verbose logging |
--help, -h | Show 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 modelsWithServiceSuffix(string)Service suffix (default: "Service")WithDocumentation()Enable docstring commentsWithOptionsObjectThreshold(int)Parameter count for options object (default: 4)
OpenAPI Filtering
WithStrictValidation()Enable strict OpenAPI validationWithOperationFilter(Func)Filter operations by predicateWithHeaderFilter(Func)Filter header parameters
Naming Transformations
Types(Func)Transform type namesPaths(Func)Transform output pathsFileNames(Func)Transform file names
File Management
CleanDestination()Clean output directory before generationAlwaysOverwrite()Always overwrite existing filesOnlyWhenModelChanged()Update only when model changesOnlyWhenNew()Write only new files, preserve existingCleanDirectories(...)Clean specific subdirectories
Diagnostics
EnableVerboseLogging()Enable detailed logging