Skip to content

Commit da93aca

Browse files
committed
chore: docs
1 parent bfb1655 commit da93aca

1 file changed

Lines changed: 55 additions & 61 deletions

File tree

README.md

Lines changed: 55 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,28 @@
11
# openapi-python
22

3-
`openapi-python` generates strongly typed Python API clients from OpenAPI specs, with route-literal dispatch and transport decoupling.
3+
`openapi-python` generates strongly typed Python API clients from OpenAPI specs, with a developer-friendly and ergonomic string-literal-based interface strongly inspired by [openapi-typescript](https://openapi-ts.dev/).
44

55
## Installation
66

7-
For protocol-only generated clients where you provide the transport:
8-
9-
```bash
10-
uv add openapi-python
11-
```
12-
137
For generated clients that use the built-in `httpx` transport:
148

159
```bash
1610
uv add "openapi-python[httpx]"
1711
```
1812

19-
## CLI
13+
For protocol-only generated clients where you provide the transport:
2014

2115
```bash
22-
uv run openapi-python generate --spec ./openapi.json --out ./generated --package my_client
16+
uv add openapi-python
2317
```
2418

25-
You can also pass the OpenAPI document directly as JSON:
2619

27-
```bash
28-
uv run openapi-python generate --spec-json "$OPENAPI_JSON" --out ./generated --package my_client
29-
```
20+
## CLI
3021

31-
For URL specs with self-signed certificates, disable verification explicitly:
22+
Generate a client from an OpenAPI spec in `openapi.json`:
3223

3324
```bash
34-
uv run openapi-python generate --spec https://example.local/openapi.json --out ./generated --no-ssl
25+
uv run openapi-python generate --spec ./openapi.json --out ./generated --package my_client
3526
```
3627

3728
## Programmatic API
@@ -50,56 +41,44 @@ result = generate_client(
5041
)
5142
```
5243

53-
To generate from an in-memory OpenAPI document, pass a JSON string instead of `spec_source`:
44+
## Using generated clients
5445

55-
```python
56-
import json
57-
from pathlib import Path
46+
Generated clients expose route-specific callables with typed `params`, `query`, `headers`, `body`, and return values.
5847

59-
from openapi_python import GenerationRequest, generate_client
48+
With the built-in `httpx` transport:
6049

61-
result = generate_client(
62-
GenerationRequest(
63-
output_dir=Path("./generated"),
64-
spec_json=json.dumps(app.openapi()),
65-
package_name="my_client",
66-
overwrite=True,
67-
)
68-
)
69-
```
70-
71-
## Extensibility
72-
73-
`GeneratorExtensions` exposes two safe hooks:
50+
```python
51+
from generated.my_client import Client
7452

75-
- `normalize_hooks`: transform the normalized model before rendering.
76-
- `render_context_hooks`: transform rendered file content map before writing.
53+
client = Client(base_url="https://api.example.com")
54+
book = client.get("/books/{book_id}")(params={"book_id": 1})
55+
```
7756

78-
Invalid extension outputs fail fast with explicit diagnostics.
57+
For async APIs:
7958

80-
## Releases
59+
```python
60+
from generated.my_client import AsyncClient
8161

82-
Releases are published from the protected `releases` branch. The package version is set manually in `pyproject.toml`, and pushing a release commit to `releases` triggers the GitHub Actions release workflow. The workflow creates the matching `vX.Y.Z` tag after checks pass.
62+
async_client = AsyncClient(base_url="https://api.example.com")
63+
book = await async_client.get("/books/{book_id}")(params={"book_id": 1})
64+
```
8365

84-
Before the first release, configure PyPI Trusted Publishing for this repository:
66+
For protocol-only clients, provide your own transport:
8567

86-
- PyPI project: `openapi-python`
87-
- GitHub workflow: `release.yml`
88-
- GitHub environment: `pypi`
68+
```python
69+
from generated.my_client import Client
8970

90-
The GitHub `pypi` environment should be limited to deployments from the `releases` branch.
71+
client = Client(base_url="https://api.example.com", transport=my_transport)
72+
book = client.get("/books/{book_id}")(params={"book_id": 1})
73+
```
9174

92-
Release steps:
9375

94-
```bash
95-
# 1. Update project.version in pyproject.toml, then commit that change.
96-
uv run python scripts/release.py --version 0.1.0
76+
## Extensibility
9777

98-
# 2. If checks pass, push the current commit to the releases branch.
99-
uv run python scripts/release.py --version 0.1.0 --push-release-branch
100-
```
78+
`GeneratorExtensions` exposes two safe hooks:
10179

102-
The release workflow verifies that the version tag does not already exist, runs checks, builds the distributions, validates them with `twine`, creates the release tag, publishes to PyPI, and creates a GitHub Release with generated notes.
80+
- `normalize_hooks`: transform the normalized model before rendering.
81+
- `render_context_hooks`: transform rendered file content map before writing.
10382

10483
## Transport Decoupling
10584

@@ -116,16 +95,7 @@ uv add "openapi-python[httpx]"
11695
uv run openapi-python generate --spec ./openapi.json --out ./generated --package my_client
11796
```
11897

119-
The generated `Client` can create its own default transport:
120-
121-
```python
122-
from generated.my_client import Client
123-
124-
client = Client(base_url="https://api.example.com")
125-
book = client.get("/books/{book_id}")(params={"book_id": 1})
126-
```
127-
128-
You can also supply preconfigured `httpx` clients:
98+
You can supply preconfigured `httpx` clients:
12999

130100
```python
131101
import httpx
@@ -199,3 +169,27 @@ client = Client(
199169
)
200170
book = client.get("/books/{book_id}")(params={"book_id": 1})
201171
```
172+
173+
## Releases
174+
175+
Releases are published from the protected `releases` branch. The package version is set manually in `pyproject.toml`, and pushing a release commit to `releases` triggers the GitHub Actions release workflow. The workflow creates the matching `vX.Y.Z` tag after checks pass.
176+
177+
Before the first release, configure PyPI Trusted Publishing for this repository:
178+
179+
- PyPI project: `openapi-python`
180+
- GitHub workflow: `release.yml`
181+
- GitHub environment: `pypi`
182+
183+
The GitHub `pypi` environment should be limited to deployments from the `releases` branch.
184+
185+
Release steps:
186+
187+
```bash
188+
# 1. Update project.version in pyproject.toml, then commit that change.
189+
uv run python scripts/release.py --version 0.1.0
190+
191+
# 2. If checks pass, push the current commit to the releases branch.
192+
uv run python scripts/release.py --version 0.1.0 --push-release-branch
193+
```
194+
195+
The release workflow verifies that the version tag does not already exist, runs checks, builds the distributions, validates them with `twine`, creates the release tag, publishes to PyPI, and creates a GitHub Release with generated notes.

0 commit comments

Comments
 (0)