Skip to main content

Lightweight Python OpenAPI 3.x → TypeScript fetch client generator. Zero Java, zero npm.

Project description

openapi-ts-fetch

PyPI CI License: MIT Python 3.10+

Lightweight Python OpenAPI 3.x → TypeScript fetch client generator. Zero Java, zero npm — just Python 3.10+ and your OpenAPI spec.

A fast, single-file alternative to the 200MB+ Java openapi-generator-cli. Generates fully typed TypeScript fetch clients with the same output structure.

Features

  • OpenAPI 3.0.3 & 3.1.x — handles both spec versions natively
  • Remote & local specs — load from URLs or local JSON/YAML files
  • Schema deduplication — identical schemas share a single model via content-hash
  • Nested extraction — inline object properties and array items become named models
  • Tag filtering — generate only the APIs you need with --tags
  • Dry-run mode — validate spec and preview what would be generated
  • No runtime dependencies — pure Python stdlib, TypeScript output uses only fetch
  • Drop-in compatible — output matches the openapi-generator TypeScript-fetch structure

Installation

pip install openapi-ts-fetch

# Or with uv
uv tool install openapi-ts-fetch

Usage

# Generate full client from local spec
openapi-ts-fetch openapi.json ./src/api-client

# Generate from a remote URL
openapi-ts-fetch https://petstore3.swagger.io/api/v3/openapi.json ./src/api-client

# Generate only specific API tags (and their referenced models)
openapi-ts-fetch openapi.json ./src/api-client --tags users,orders

# Override BASE_PATH in generated runtime.ts
openapi-ts-fetch openapi.json ./src/api-client --base-path /api/v1

# Validate spec without generating (dry-run)
openapi-ts-fetch openapi.json ./src/api-client --dry-run

# Check version
openapi-ts-fetch --version

Output Structure

src/api-client/
├── runtime.ts          # Configuration, BaseAPI, middleware, fetch helpers
├── index.ts            # Barrel exports
├── apis/
│   ├── index.ts
│   ├── UsersApi.ts     # One class per OpenAPI tag
│   └── OrdersApi.ts
└── models/
    ├── index.ts
    ├── User.ts          # Interface + FromJSON/ToJSON
    └── CreateUserRequest.ts

Using the Generated Client

import { Configuration, UsersApi } from './api-client'

const config = new Configuration({
  basePath: 'https://api.example.com',
  accessToken: async () => getMyToken(),
})

const users = new UsersApi(config)

// Fully typed request and response
const user = await users.getUser({ id: '123' })
console.log(user.name)

Tag Filtering

When you only need a subset of your API in a particular app, use --tags to generate a lean client:

# Full API has 26 tags and 220 models, but your app only uses 'shl'
openapi-ts-fetch openapi.json ./src/api-client --tags shl

# Output: 1 API class, 3 models (only transitively referenced ones)

This is especially useful in monorepos where different apps consume different parts of the same backend API.

Comparison

openapi-ts-fetch openapi-generator-cli
Runtime Python 3.10+ (~1000 LOC) Java 11+ (~200MB JAR)
Install pip install or copy 2 files Docker / Java / npm wrapper
Speed ~1s for 200+ models ~10s+ for same spec
Tag filtering Built-in --tags Templates + config
Schema dedup Content-hash based Limited
Output TypeScript fetch TypeScript fetch (+ 40 others)

Schema Naming Strategy

  1. title field — uses the schema's title if present (frameworks like Elysia/TypeBox set these automatically)
  2. Content-hash dedup — identical schemas with the same title share a single model
  3. Nested objectsParentName + PropertyName (PascalCase)
  4. Array itemsParentName + PropertyName + "Inner"
  5. FallbackOperationId + StatusCode + "Response" / "Request"

License

MIT — Max Health Inc.

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

openapi_ts_fetch-0.2.0.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openapi_ts_fetch-0.2.0-py3-none-any.whl (25.3 kB view details)

Uploaded Python 3

File details

Details for the file openapi_ts_fetch-0.2.0.tar.gz.

File metadata

  • Download URL: openapi_ts_fetch-0.2.0.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for openapi_ts_fetch-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b15bc8c77cc0995cba7294e1769400ea8ec0eb7239861eedefde08a71757b6f4
MD5 a482bfaaab5f7bfcc2a25ee253b77ec6
BLAKE2b-256 896fd232b3cb9285d30d80900920cc01005c6bd63827adbb4d995ace7ed9f2d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for openapi_ts_fetch-0.2.0.tar.gz:

Publisher: publish.yml on Max-Health-Inc/openapi-ts-fetch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file openapi_ts_fetch-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for openapi_ts_fetch-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ae3efd4d618569e70aacbd0da30953e89b54cb7f525a7c71f6ded3c01fc94b6
MD5 3783044ecdb032221b49ab9a78a62feb
BLAKE2b-256 56d58109bf9bbdfdc94ce0e32de0228c5ecc01ab57a5c4853266de64ddd50e76

See more details on using hashes here.

Provenance

The following attestation bundles were made for openapi_ts_fetch-0.2.0-py3-none-any.whl:

Publisher: publish.yml on Max-Health-Inc/openapi-ts-fetch

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