npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@metaengine/openapi-python

v0.9.0

Published

Generate Python/FastAPI services and models from OpenAPI specifications with Pydantic models, httpx client, and async/await support for Python 3.12+

Downloads

106

Readme

@metaengine/openapi-python

Generate Python/FastAPI services and models from OpenAPI specifications.

Features

  • Python 3.12+ - Modern Python with type hints
  • FastAPI - High-performance async API framework
  • Pydantic V2 - Optional data validation with type hints (opt-in)
  • httpx - Modern async HTTP client
  • Type Safe - Full type hint coverage
  • Async/Await - Native async support

Installation

npm install --save-dev @metaengine/openapi-python

Or use directly with npx:

npx @metaengine/openapi-python <input> <output>

Requirements

  • Node.js 14.0 or later (for running the CLI)
  • .NET 8.0 or later runtime (Download)
  • Python 3.12 or later (for using generated code)

Usage

With npm scripts (Recommended when installed locally)

If you installed the package with npm install, add a script to your package.json:

{
  "scripts": {
    "generate:api": "metaengine-openapi-python api.yaml ./src/api --pydantic-models --documentation --camel-case-aliases"
  }
}

Then run:

npm run generate:api

With npx (One-off usage or without installation)

Use npx for trying out the tool or in CI/CD pipelines:

# Recommended (with Pydantic models, documentation, and camelCase aliases)
npx @metaengine/openapi-python api.yaml ./generated \
  --pydantic-models \
  --documentation \
  --camel-case-aliases

# Basic (minimal setup, plain dataclasses)
npx @metaengine/openapi-python api.yaml ./generated

# Filter by tags (only specific endpoints)
npx @metaengine/openapi-python api.yaml ./generated \
  --include-tags users,auth \
  --pydantic-models \
  --documentation

# From URL with Pydantic models
npx @metaengine/openapi-python https://api.example.com/openapi.json ./generated \
  --pydantic-models \
  --documentation \
  --camel-case-aliases

Note: When the package is installed locally, npx will use that version instead of downloading a new one.

CLI Options

| Option | Description | Default | |--------|-------------|---------| | --include-tags <tags> | Filter by OpenAPI tags (comma-separated, case-insensitive) | - | | --service-suffix <suffix> | Service naming suffix | Service | | --options-threshold <n> | Parameter count for options object | 4 | | --documentation | Generate docstring comments | false | | --pydantic-models | Enable Pydantic v2 models for validation (opt-in) | false | | --camel-case-aliases | Generate camelCase field aliases for Pydantic models | false | | --strict-validation | Enable strict OpenAPI validation | false | | --verbose | Enable verbose logging | false | | --help, -h | Show help message | - |

Generated Code Structure

generated/
├── models/          # Pydantic models
│   ├── user.py
│   ├── order.py
│   └── ...
└── services/        # API service classes
    ├── users_service.py
    ├── orders_service.py
    └── ...

Usage Examples

Install Dependencies

Install the required Python packages:

# Basic dependencies
pip install httpx typing-extensions

# Additional dependencies for Pydantic models (when using --pydantic-models)
pip install fastapi pydantic

Or add to your requirements.txt:

# Required
httpx>=0.27.0
typing-extensions>=4.0.0

# Optional: for Pydantic models (--pydantic-models flag)
fastapi>=0.115.0
pydantic>=2.0.0

Basic API Calls

from generated.services.users_service import UsersService

# Initialize service
users_service = UsersService(base_url="https://api.example.com")

# Fetch users
users = await users_service.get_users()

# Create a user
new_user = await users_service.create_user(name="John", email="[email protected]")

With FastAPI

from fastapi import FastAPI, Depends
from generated.services.users_service import UsersService
from generated.models.user import User

app = FastAPI()

def get_users_service():
    return UsersService(base_url="https://api.example.com")

@app.get("/api/users")
async def get_users(service: UsersService = Depends(get_users_service)) -> list[User]:
    return await service.get_users()

@app.post("/api/users")
async def create_user(
    user: User,
    service: UsersService = Depends(get_users_service)
) -> User:
    return await service.create_user(name=user.name, email=user.email)

Pydantic Models (with --pydantic-models flag)

When using --pydantic-models, generated Pydantic models provide validation and serialization:

from generated.models.user import User

# Create with validation
user = User(name="John", email="[email protected]")

# Serialize to dict
user_dict = user.model_dump()

# Serialize to JSON
user_json = user.model_dump_json()

# Parse from JSON
user = User.model_validate_json('{"name": "John", "email": "[email protected]"}')

CamelCase Aliases (with --pydantic-models and --camel-case-aliases)

When using both --pydantic-models and --camel-case-aliases, Pydantic models will accept both snake_case and camelCase:

from generated.models.user import User

# Both work!
user1 = User(first_name="John", last_name="Doe")
user2 = User(firstName="John", lastName="Doe")

# Output is snake_case by default
print(user1.first_name)  # "John"

Framework Support

Currently supports:

  • FastAPI (default) - High-performance async API framework

Coming soon:

  • Django - Use --framework django (planned)
  • Flask - Use --framework flask (planned)

Type Hints

All generated code includes complete type hints for:

  • Function parameters
  • Return types
  • Pydantic model fields
  • Optional/required fields

Compatible with:

  • mypy
  • pyright
  • pylance

License

MIT

Support

For issues and feature requests, please visit: https://github.com/meta-engine/openapi-python/issues