https://github.com/hey-api/openapi-python
π OpenAPI to Python code generator. Production-grade SDKs and Pydantic models.
https://github.com/hey-api/openapi-python
api-client code-generation codegen fastapi openapi openapi-generator pydantic python rest-api sdk swagger
Last synced: about 10 hours ago
JSON representation
π OpenAPI to Python code generator. Production-grade SDKs and Pydantic models.
- Host: GitHub
- URL: https://github.com/hey-api/openapi-python
- Owner: hey-api
- License: mit
- Created: 2026-06-19T09:21:16.000Z (22 days ago)
- Default Branch: main
- Last Pushed: 2026-06-28T16:04:16.000Z (12 days ago)
- Last Synced: 2026-06-28T18:05:29.874Z (12 days ago)
- Topics: api-client, code-generation, codegen, fastapi, openapi, openapi-generator, pydantic, python, rest-api, sdk, swagger
- Language: TypeScript
- Homepage: https://heyapi.dev/docs/openapi/python/get-started
- Size: 178 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
> [!NOTE]
> Read-only mirror of [`@hey-api/openapi-python`](https://npmjs.com/package/@hey-api/openapi-python) from the [hey-api](https://github.com/hey-api/hey-api) monorepo. Issues, pull requests, and contributions go to the [main repository](https://github.com/hey-api/hey-api).
OpenAPI Python
βThe ecosystem trusted by TypeScript developers is coming to Python codebases.β
β Lubos, Founder of Hey API
Manual
Β β’Β
Issues
Β β’Β
Contribute
## About
The OpenAPI to Python code generator.
Generate production-grade SDKs and Pydantic models.
Part of the Hey API ecosystem.
## Features
- production-grade code that compiles
- runs in any Node.js 22+ environment
- accepts any OpenAPI specification
- core plugin for SDKs
- HTTP client for HTTPX
- highly customizable via plugins
- [sync with Hey API Registry](https://heyapi.dev/docs/openapi/typescript/integrations) for spec management
## Contributing
Want to see your code in products used by millions?
Start with our [Contributing](https://heyapi.dev/docs/openapi/typescript/community/contributing) guide and release your first feature.
## Sponsors
Partners behind the future of API tooling. [Become a sponsor](https://github.com/sponsors/hey-api).
Gold
The open source coding agent.
opencode.ai
Silver
scalar.com
fastapi.tiangolo.com
getunblocked.com
Bronze
## Quick Start
The fastest way to use `@hey-api/openapi-python` is via npx
```sh
npx @hey-api/openapi-python -i hey-api/backend -o src/client
```
Congratulations on creating your first client! π You can learn more about the generated files on the [Output](https://heyapi.dev/docs/openapi/python/output) page.
## Installation
You can download `@hey-api/openapi-python` from npm using your favorite package manager.
#### npm
```sh
npm install @hey-api/openapi-python -D -E
```
#### pnpm
```sh
pnpm add @hey-api/openapi-python -D -E
```
#### yarn
```sh
yarn add @hey-api/openapi-python -D -E
```
#### bun
```sh
bun add @hey-api/openapi-python -D
```
### Versioning
This package is in [initial development](https://semver.org/#spec-item-4). Please pin an exact version so you can safely upgrade when you're ready.
We publish [migration notes](https://heyapi.dev/docs/openapi/python/migrating) for every breaking release. You might not be impacted by a breaking change if you don't use the affected features.
## Usage
### CLI
Most people run `@hey-api/openapi-python` via CLI. To do that, add a script to your `package.json` file which will make `openapi-python` executable through script.
```json
"scripts": {
"openapi-python": "openapi-python"
}
```
The above script can be executed by running `npm run openapi-python` or equivalent command in other package managers. Next, we will create a [configuration](https://heyapi.dev/docs/openapi/python/configuration) file and move our options from Quick Start to it.
### Node.js
You can also generate output programmatically by calling `createClient()` in a JavaScript/TypeScript file.
#### `script.ts`
```ts
import { createClient } from '@hey-api/openapi-python';
createClient({
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: 'src/client',
});
```
## Configuration
`@hey-api/openapi-python` supports loading configuration from any file inside your project root folder supported by [jiti loader](https://github.com/unjs/c12?tab=readme-ov-file#-features). Below are the most common file formats.
#### `openapi-python.config.ts`
```js
import { defineConfig } from '@hey-api/openapi-python';
export default defineConfig({
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: 'src/client',
});
```
#### `openapi-python.config.cjs`
```js
/** @type {import('@hey-api/openapi-python').UserConfig} */
module.exports = {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: 'src/client',
};
```
#### `openapi-python.config.mjs`
```js
/** @type {import('@hey-api/openapi-python').UserConfig} */
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: 'src/client',
};
```
Alternatively, you can use `openapi-python.config.js` and configure the export statement depending on your project setup.
### Input
You must set the input so we can load your OpenAPI specification. It can be a path or URL, object containing a path or URL, or an object representing an OpenAPI specification. Hey API supports all valid OpenAPI versions and file formats.
> If you use an HTTPS URL with a self-signed certificate in development, you will need to set [`NODE_TLS_REJECT_UNAUTHORIZED=0`](https://github.com/hey-api/hey-api/issues/276#issuecomment-2043143501) in your environment.
### Output
You must set the output so we know where to generate your files. It can be a path to the destination folder or an object containing the destination folder path and optional settings.
> You should treat the output folder as a dependency. Do not directly modify its contents as your changes might be erased when you run `@hey-api/openapi-python` again.
## Parser
We parse your input before making it available to plugins. While configuring the parser is optional, it's the perfect place to modify or validate your input if needed.
## Plugins
Plugins are responsible for generating artifacts from your input. By default, Hey API will generate Pydantic models and SDK from your OpenAPI specification. You can add, remove, or customize any of the plugins. In fact, we highly encourage you to do so!
### Client
Clients are responsible for sending the actual HTTP requests. We default to HTTPX client if you're generating SDKs, but you can choose a different option from the available clients.
### Available Clients
- [`@hey-api/client-httpx`](https://heyapi.dev/docs/openapi/python/clients/httpx)
### Proposed Clients (Vote to Prioritize)
The following clients are roadmap proposals and are not started yet. You can help us prioritize them by voting on [GitHub](https://github.com/hey-api/hey-api/issues?q=state%3Aopen%20label%3A%22vote%20%F0%9F%93%A9%22).
- [`@hey-api/client-aiohttp`](https://heyapi.dev/docs/openapi/python/clients/aiohttp)
- [`@hey-api/client-requests`](https://heyapi.dev/docs/openapi/python/clients/requests)
- [`@hey-api/client-urllib3`](https://heyapi.dev/docs/openapi/python/clients/urllib3)
Don't see your client? [Build your own](https://heyapi.dev/docs/openapi/python/clients/custom) or let us know your interest by [opening an issue](https://github.com/hey-api/hey-api/issues).
### Available Plugins
These plugins help reduce boilerplate associated with third-party dependencies. Hey API natively supports the most popular packages. Please open an issue on [GitHub](https://github.com/hey-api/hey-api/issues) if you'd like us to support your favorite package.
- [`pydantic`](https://heyapi.dev/docs/openapi/python/plugins/pydantic)
### Proposed Plugins (Vote to Prioritize)
The following plugins are roadmap proposals and are not started yet. You can help us prioritize them by voting on [GitHub](https://github.com/hey-api/hey-api/issues?q=state%3Aopen%20label%3A%22vote%20%F0%9F%93%A9%22).
- [Attrs](https://heyapi.dev/docs/openapi/python/plugins/attrs)
- [Dataclasses](https://heyapi.dev/docs/openapi/python/plugins/dataclasses)
- [Factory Boy](https://heyapi.dev/docs/openapi/python/plugins/factory-boy)
- [Faker](https://heyapi.dev/docs/openapi/python/plugins/faker)
- [Marshmallow](https://heyapi.dev/docs/openapi/python/plugins/marshmallow)
- [Mimesis](https://heyapi.dev/docs/openapi/python/plugins/mimesis)
Don't see your plugin? [Build your own](https://heyapi.dev/docs/openapi/python/plugins/custom) or let us know your interest by [opening an issue](https://github.com/hey-api/hey-api/issues).
## Migrating
You can learn more on the [Migrating](https://heyapi.dev/docs/openapi/python/migrating) page.
## License
Released under the [MIT License](https://github.com/hey-api/hey-api/blob/main/LICENSE.md).