otterapi 0.1.7__tar.gz → 0.1.9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {otterapi-0.1.7 → otterapi-0.1.9}/.gitignore +1 -0
- otterapi-0.1.9/LICENSE +22 -0
- otterapi-0.1.7/README.md → otterapi-0.1.9/PKG-INFO +92 -10
- otterapi-0.1.7/PKG-INFO → otterapi-0.1.9/README.md +60 -40
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/__init__.py +4 -4
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/cli.py +35 -22
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/codegen/_openapi_adapter.py +1 -2
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/codegen/ast_utils.py +18 -12
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/codegen/client.py +226 -47
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/codegen/codegen.py +321 -207
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/codegen/endpoints.py +72 -36
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/codegen/pagination.py +2 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/codegen/runtime/_export.py +49 -26
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/codegen/schema.py +65 -9
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/codegen/splitting.py +30 -10
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/codegen/types.py +64 -42
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/codegen/utils.py +6 -3
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/config.py +53 -1
- otterapi-0.1.9/otterapi/openapi/_lenient.py +93 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/openapi/v2/v2.py +103 -51
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/openapi/v3/v3.py +26 -22
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/openapi/v3_1/v3_1.py +54 -52
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/openapi/v3_2/v3_2.py +54 -52
- otterapi-0.1.9/otterapi/py.typed +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_client_retry_lifecycle.py +137 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_codegen.py +177 -1
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_codegen_structure.py +1 -1
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_export.py +12 -1
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_extra_forbid.py +1 -0
- otterapi-0.1.9/otterapi/tests/test_lenient.py +255 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_nullable_upgrade.py +5 -1
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_pagination.py +102 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_schema_constraints.py +6 -1
- {otterapi-0.1.7 → otterapi-0.1.9}/pyproject.toml +13 -16
- otterapi-0.1.7/otterapi/tests/test_regen_script.py +0 -50
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/__main__.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/codegen/__init__.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/codegen/_body_builder.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/codegen/_features.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/codegen/dataframes.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/codegen/export.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/codegen/runtime/__init__.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/codegen/runtime/_client_stub.py.tpl +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/codegen/runtime/_concurrency.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/codegen/runtime/_dataframe.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/codegen/runtime/_models_mixin.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/codegen/runtime/_pagination.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/codegen/runtime/_retry.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/exceptions.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/openapi/__init__.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/openapi/constants.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/openapi/v2/__init__.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/openapi/v2/spec.json +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/openapi/v3/__init__.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/openapi/v3/spec.json +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/openapi/v3_1/__init__.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/openapi/v3_1/spec.json +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/openapi/v3_2/__init__.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/openapi/v3_2/spec.json +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/openapi/warnings.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/__init__.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/fixtures/__init__.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/fixtures/golden/constraints/spec.yaml +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/fixtures/golden/dataframe/config.yaml +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/fixtures/golden/dataframe/spec.yaml +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/fixtures/golden/discriminator/spec.yaml +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/fixtures/golden/paginated/config.yaml +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/fixtures/golden/paginated/spec.yaml +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_ast_utils.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_body_builder.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_codegen_edge_cases.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_concurrency_runtime.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_config_errors.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_dataframe.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_discriminated_unions.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_exceptions.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_feature_modules.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_html_repr.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_init_scaffold.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_not_schema.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_openapi_adapter.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_openapi_support.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_openapi_upgrade.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_per_status_errors.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_public_api.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_recursive_schema.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_retry_runtime.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_runtime_guards.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_smoke_generated_client.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_splitting_config.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_splitting_integration.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_splitting_resolver.py +0 -0
- {otterapi-0.1.7 → otterapi-0.1.9}/otterapi/tests/test_splitting_tree.py +0 -0
otterapi-0.1.9/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dan Plischke
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
@@ -1,6 +1,38 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: otterapi
|
|
3
|
+
Version: 0.1.9
|
|
4
|
+
Summary: A cute otter that turns OpenAPI & Swagger specs into type-safe, async Python clients — powered by httpx and Pydantic.
|
|
5
|
+
Project-URL: Source, https://github.com/danplischke/otterapi
|
|
6
|
+
Author: Dan Plischke
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Operating System :: MacOS
|
|
11
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
12
|
+
Classifier: Operating System :: POSIX
|
|
13
|
+
Classifier: Operating System :: Unix
|
|
14
|
+
Classifier: Programming Language :: Python
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Topic :: Utilities
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Requires-Dist: httpx~=0.28.1
|
|
24
|
+
Requires-Dist: pydantic-settings~=2.11.0
|
|
25
|
+
Requires-Dist: pydantic[email]~=2.12.3
|
|
26
|
+
Requires-Dist: pyyaml~=6.0.3
|
|
27
|
+
Requires-Dist: typer~=0.20.0
|
|
28
|
+
Requires-Dist: universal-pathlib~=0.3.4
|
|
29
|
+
Provides-Extra: parquet
|
|
30
|
+
Requires-Dist: pyarrow>=15; extra == 'parquet'
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
1
33
|
# 🦦 OtterAPI
|
|
2
34
|
|
|
3
|
-
> *A cute
|
|
35
|
+
> *A cute otter that turns OpenAPI & Swagger specs into type-safe, async Python clients — powered by httpx and Pydantic.*
|
|
4
36
|
|
|
5
37
|
**OtterAPI** is a sleek Python library that transforms OpenAPI specifications into clean, type-safe client code with Pydantic models and httpx-based HTTP clients.
|
|
6
38
|
|
|
@@ -9,6 +41,7 @@
|
|
|
9
41
|
- **Type-Safe Code Generation** - Generates Pydantic models and fully typed endpoint functions
|
|
10
42
|
- **Sync & Async Support** - Generate both synchronous and asynchronous API clients
|
|
11
43
|
- **OpenAPI 3.x Support** - Full support for OpenAPI 3.0, 3.1, and 3.2 specifications
|
|
44
|
+
- **Strict or Lenient Validation** - Fail fast on malformed specs, or drop stray fields with `--lenient` (vendor `x-*` extensions always preserved)
|
|
12
45
|
- **Module Splitting** - Organize large APIs into multiple organized files
|
|
13
46
|
- **Pagination** - Auto-detect or configure offset, cursor, page, and link-header pagination
|
|
14
47
|
- **DataFrame Conversion** - Generate pandas/polars DataFrame methods for list endpoints
|
|
@@ -44,14 +77,14 @@ otter generate
|
|
|
44
77
|
3. Use the generated code:
|
|
45
78
|
|
|
46
79
|
```python
|
|
47
|
-
from petstore_client import get_pet_by_id,
|
|
80
|
+
from petstore_client import get_pet_by_id, async_get_pet_by_id
|
|
48
81
|
|
|
49
82
|
# Synchronous usage
|
|
50
83
|
pet = get_pet_by_id(pet_id=123)
|
|
51
84
|
|
|
52
85
|
# Asynchronous usage
|
|
53
86
|
import asyncio
|
|
54
|
-
pet = asyncio.run(
|
|
87
|
+
pet = asyncio.run(async_get_pet_by_id(pet_id=123))
|
|
55
88
|
```
|
|
56
89
|
|
|
57
90
|
---
|
|
@@ -108,6 +141,7 @@ These sit at the root of your config file, outside of `documents:`.
|
|
|
108
141
|
| `format_output` | bool | `true` | Format generated code with ruff/black |
|
|
109
142
|
| `validate_output` | bool | `true` | Validate generated code syntax after writing |
|
|
110
143
|
| `create_py_typed` | bool | `true` | Create `py.typed` marker files |
|
|
144
|
+
| `lenient` | bool | `false` | Drop unrecognized, invalid fields instead of failing (see [Strict vs Lenient Validation](#-strict-vs-lenient-validation)) |
|
|
111
145
|
|
|
112
146
|
```yaml
|
|
113
147
|
format_output: true
|
|
@@ -134,9 +168,26 @@ Each entry under `documents:` supports these fields:
|
|
|
134
168
|
| `generate_async` | bool | `true` | Generate async endpoint functions |
|
|
135
169
|
| `generate_sync` | bool | `true` | Generate sync endpoint functions |
|
|
136
170
|
| `client_class_name` | string | from API title | Override the generated client class name |
|
|
171
|
+
| `function_naming` | `operation_id` \| `path` | `operation_id` | How to name endpoint functions. `path` derives names from the HTTP method and URL path — use it for specs that reuse one `operationId` across many paths |
|
|
137
172
|
| `include_paths` | list | `null` | Glob patterns — only matching paths are generated |
|
|
138
173
|
| `exclude_paths` | list | `null` | Glob patterns — matching paths are skipped (applied after `include_paths`) |
|
|
139
174
|
|
|
175
|
+
#### Function Naming
|
|
176
|
+
|
|
177
|
+
By default, endpoint function names come from each operation's `operationId`. Some
|
|
178
|
+
specs (notably Swashbuckle/.NET output) reuse a single `operationId` across many
|
|
179
|
+
distinct paths, which produces a pile of numerically-suffixed duplicates like
|
|
180
|
+
`feed_changes`, `feed_changes_2`, … `feed_changes_43`. Set `function_naming: path`
|
|
181
|
+
to derive names from the HTTP method and URL path instead, giving distinct,
|
|
182
|
+
descriptive names:
|
|
183
|
+
|
|
184
|
+
```yaml
|
|
185
|
+
documents:
|
|
186
|
+
- source: https://api.example.com/swagger.json
|
|
187
|
+
output: ./client
|
|
188
|
+
function_naming: path # get_v1_feed_trial_changes, get_v1_feed_hcp_profile_changes, ...
|
|
189
|
+
```
|
|
190
|
+
|
|
140
191
|
#### Path Filtering
|
|
141
192
|
|
|
142
193
|
```yaml
|
|
@@ -173,6 +224,34 @@ You can also configure a single document entirely via environment variables (no
|
|
|
173
224
|
| `OTTER_MODELS_FILE` | Models filename |
|
|
174
225
|
| `OTTER_ENDPOINTS_FILE` | Endpoints filename |
|
|
175
226
|
|
|
227
|
+
### 🔎 Strict vs Lenient Validation
|
|
228
|
+
|
|
229
|
+
By default, OtterAPI validates specs **strictly**: an unrecognized or
|
|
230
|
+
structurally-invalid field aborts generation with a clear error, catching
|
|
231
|
+
malformed specs early.
|
|
232
|
+
|
|
233
|
+
Some real-world specs (especially auto-generated Swagger 2.0 documents) carry
|
|
234
|
+
stray, non-standard keys. Set `lenient: true` — or pass `--lenient` — to **drop**
|
|
235
|
+
those fields instead of failing. Each dropped key is reported as a warning.
|
|
236
|
+
|
|
237
|
+
```yaml
|
|
238
|
+
lenient: true
|
|
239
|
+
|
|
240
|
+
documents:
|
|
241
|
+
- source: https://api.example.com/openapi.json
|
|
242
|
+
output: ./client
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
otter generate --lenient
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
**Vendor extensions are always preserved.** OpenAPI specification extensions
|
|
250
|
+
(`x-*`) are kept in both strict and lenient mode. The only exception is the
|
|
251
|
+
type-discriminated security-scheme objects (`apiKey`, `http`, `oauth2`,
|
|
252
|
+
`openIdConnect`), which still reject unknown keys so their variant stays
|
|
253
|
+
unambiguous.
|
|
254
|
+
|
|
176
255
|
---
|
|
177
256
|
|
|
178
257
|
## 📦 Module Splitting
|
|
@@ -445,14 +524,14 @@ pagination:
|
|
|
445
524
|
### Usage
|
|
446
525
|
|
|
447
526
|
```python
|
|
448
|
-
from client import list_users_iter,
|
|
527
|
+
from client import list_users_iter, async_list_users_iter
|
|
449
528
|
|
|
450
529
|
# Iterate all users (handles pagination automatically)
|
|
451
530
|
for user in list_users_iter():
|
|
452
531
|
print(user.name)
|
|
453
532
|
|
|
454
533
|
# Async variant
|
|
455
|
-
async for user in
|
|
534
|
+
async for user in async_list_users_iter():
|
|
456
535
|
print(user.name)
|
|
457
536
|
```
|
|
458
537
|
|
|
@@ -479,7 +558,7 @@ documents:
|
|
|
479
558
|
| Original | Pandas | Polars |
|
|
480
559
|
|----------|--------|--------|
|
|
481
560
|
| `get_users()` | `get_users_df()` | `get_users_pl()` |
|
|
482
|
-
| `
|
|
561
|
+
| `async_get_users()` | `async_get_users_df()` | `async_get_users_pl()` |
|
|
483
562
|
|
|
484
563
|
### Usage
|
|
485
564
|
|
|
@@ -649,8 +728,8 @@ response_unwrap:
|
|
|
649
728
|
```python
|
|
650
729
|
from client import get_user, create_user, list_orders
|
|
651
730
|
|
|
652
|
-
# Async versions are prefixed with '
|
|
653
|
-
from client import
|
|
731
|
+
# Async versions are prefixed with 'async_'
|
|
732
|
+
from client import async_get_user, async_create_user, async_list_orders
|
|
654
733
|
|
|
655
734
|
# Sync
|
|
656
735
|
user = get_user(user_id=123)
|
|
@@ -659,7 +738,7 @@ user = get_user(user_id=123)
|
|
|
659
738
|
import asyncio
|
|
660
739
|
|
|
661
740
|
async def main():
|
|
662
|
-
user = await
|
|
741
|
+
user = await async_get_user(user_id=123)
|
|
663
742
|
|
|
664
743
|
asyncio.run(main())
|
|
665
744
|
```
|
|
@@ -685,7 +764,7 @@ client = Client(
|
|
|
685
764
|
user = client.get_user(user_id=123)
|
|
686
765
|
|
|
687
766
|
async def main():
|
|
688
|
-
user = await client.
|
|
767
|
+
user = await client.async_get_user(user_id=123)
|
|
689
768
|
```
|
|
690
769
|
|
|
691
770
|
### Working with Models
|
|
@@ -709,6 +788,9 @@ otter generate
|
|
|
709
788
|
# Generate from specific config file
|
|
710
789
|
otter generate -c my-config.yml
|
|
711
790
|
|
|
791
|
+
# Tolerate malformed specs (drop unknown/invalid fields with a warning)
|
|
792
|
+
otter generate --lenient
|
|
793
|
+
|
|
712
794
|
# Initialize a new config file
|
|
713
795
|
otter init
|
|
714
796
|
|
|
@@ -1,36 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: otterapi
|
|
3
|
-
Version: 0.1.7
|
|
4
|
-
Summary: A cute little companion that generates type-safe clients from OpenAPI documents.
|
|
5
|
-
Project-URL: Source, https://github.com/danplischke/otter
|
|
6
|
-
Author: Dan Plischke
|
|
7
|
-
License-Expression: MIT
|
|
8
|
-
Classifier: Development Status :: 3 - Alpha
|
|
9
|
-
Classifier: Operating System :: MacOS
|
|
10
|
-
Classifier: Operating System :: Microsoft :: Windows
|
|
11
|
-
Classifier: Operating System :: POSIX
|
|
12
|
-
Classifier: Operating System :: Unix
|
|
13
|
-
Classifier: Programming Language :: Python
|
|
14
|
-
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
-
Classifier: Topic :: Utilities
|
|
20
|
-
Requires-Python: >=3.10
|
|
21
|
-
Requires-Dist: httpx~=0.28.1
|
|
22
|
-
Requires-Dist: pydantic-settings~=2.11.0
|
|
23
|
-
Requires-Dist: pydantic[email]~=2.12.3
|
|
24
|
-
Requires-Dist: pyyaml~=6.0.3
|
|
25
|
-
Requires-Dist: typer~=0.20.0
|
|
26
|
-
Requires-Dist: universal-pathlib~=0.3.4
|
|
27
|
-
Provides-Extra: parquet
|
|
28
|
-
Requires-Dist: pyarrow>=15; extra == 'parquet'
|
|
29
|
-
Description-Content-Type: text/markdown
|
|
30
|
-
|
|
31
1
|
# 🦦 OtterAPI
|
|
32
2
|
|
|
33
|
-
> *A cute
|
|
3
|
+
> *A cute otter that turns OpenAPI & Swagger specs into type-safe, async Python clients — powered by httpx and Pydantic.*
|
|
34
4
|
|
|
35
5
|
**OtterAPI** is a sleek Python library that transforms OpenAPI specifications into clean, type-safe client code with Pydantic models and httpx-based HTTP clients.
|
|
36
6
|
|
|
@@ -39,6 +9,7 @@ Description-Content-Type: text/markdown
|
|
|
39
9
|
- **Type-Safe Code Generation** - Generates Pydantic models and fully typed endpoint functions
|
|
40
10
|
- **Sync & Async Support** - Generate both synchronous and asynchronous API clients
|
|
41
11
|
- **OpenAPI 3.x Support** - Full support for OpenAPI 3.0, 3.1, and 3.2 specifications
|
|
12
|
+
- **Strict or Lenient Validation** - Fail fast on malformed specs, or drop stray fields with `--lenient` (vendor `x-*` extensions always preserved)
|
|
42
13
|
- **Module Splitting** - Organize large APIs into multiple organized files
|
|
43
14
|
- **Pagination** - Auto-detect or configure offset, cursor, page, and link-header pagination
|
|
44
15
|
- **DataFrame Conversion** - Generate pandas/polars DataFrame methods for list endpoints
|
|
@@ -74,14 +45,14 @@ otter generate
|
|
|
74
45
|
3. Use the generated code:
|
|
75
46
|
|
|
76
47
|
```python
|
|
77
|
-
from petstore_client import get_pet_by_id,
|
|
48
|
+
from petstore_client import get_pet_by_id, async_get_pet_by_id
|
|
78
49
|
|
|
79
50
|
# Synchronous usage
|
|
80
51
|
pet = get_pet_by_id(pet_id=123)
|
|
81
52
|
|
|
82
53
|
# Asynchronous usage
|
|
83
54
|
import asyncio
|
|
84
|
-
pet = asyncio.run(
|
|
55
|
+
pet = asyncio.run(async_get_pet_by_id(pet_id=123))
|
|
85
56
|
```
|
|
86
57
|
|
|
87
58
|
---
|
|
@@ -138,6 +109,7 @@ These sit at the root of your config file, outside of `documents:`.
|
|
|
138
109
|
| `format_output` | bool | `true` | Format generated code with ruff/black |
|
|
139
110
|
| `validate_output` | bool | `true` | Validate generated code syntax after writing |
|
|
140
111
|
| `create_py_typed` | bool | `true` | Create `py.typed` marker files |
|
|
112
|
+
| `lenient` | bool | `false` | Drop unrecognized, invalid fields instead of failing (see [Strict vs Lenient Validation](#-strict-vs-lenient-validation)) |
|
|
141
113
|
|
|
142
114
|
```yaml
|
|
143
115
|
format_output: true
|
|
@@ -164,9 +136,26 @@ Each entry under `documents:` supports these fields:
|
|
|
164
136
|
| `generate_async` | bool | `true` | Generate async endpoint functions |
|
|
165
137
|
| `generate_sync` | bool | `true` | Generate sync endpoint functions |
|
|
166
138
|
| `client_class_name` | string | from API title | Override the generated client class name |
|
|
139
|
+
| `function_naming` | `operation_id` \| `path` | `operation_id` | How to name endpoint functions. `path` derives names from the HTTP method and URL path — use it for specs that reuse one `operationId` across many paths |
|
|
167
140
|
| `include_paths` | list | `null` | Glob patterns — only matching paths are generated |
|
|
168
141
|
| `exclude_paths` | list | `null` | Glob patterns — matching paths are skipped (applied after `include_paths`) |
|
|
169
142
|
|
|
143
|
+
#### Function Naming
|
|
144
|
+
|
|
145
|
+
By default, endpoint function names come from each operation's `operationId`. Some
|
|
146
|
+
specs (notably Swashbuckle/.NET output) reuse a single `operationId` across many
|
|
147
|
+
distinct paths, which produces a pile of numerically-suffixed duplicates like
|
|
148
|
+
`feed_changes`, `feed_changes_2`, … `feed_changes_43`. Set `function_naming: path`
|
|
149
|
+
to derive names from the HTTP method and URL path instead, giving distinct,
|
|
150
|
+
descriptive names:
|
|
151
|
+
|
|
152
|
+
```yaml
|
|
153
|
+
documents:
|
|
154
|
+
- source: https://api.example.com/swagger.json
|
|
155
|
+
output: ./client
|
|
156
|
+
function_naming: path # get_v1_feed_trial_changes, get_v1_feed_hcp_profile_changes, ...
|
|
157
|
+
```
|
|
158
|
+
|
|
170
159
|
#### Path Filtering
|
|
171
160
|
|
|
172
161
|
```yaml
|
|
@@ -203,6 +192,34 @@ You can also configure a single document entirely via environment variables (no
|
|
|
203
192
|
| `OTTER_MODELS_FILE` | Models filename |
|
|
204
193
|
| `OTTER_ENDPOINTS_FILE` | Endpoints filename |
|
|
205
194
|
|
|
195
|
+
### 🔎 Strict vs Lenient Validation
|
|
196
|
+
|
|
197
|
+
By default, OtterAPI validates specs **strictly**: an unrecognized or
|
|
198
|
+
structurally-invalid field aborts generation with a clear error, catching
|
|
199
|
+
malformed specs early.
|
|
200
|
+
|
|
201
|
+
Some real-world specs (especially auto-generated Swagger 2.0 documents) carry
|
|
202
|
+
stray, non-standard keys. Set `lenient: true` — or pass `--lenient` — to **drop**
|
|
203
|
+
those fields instead of failing. Each dropped key is reported as a warning.
|
|
204
|
+
|
|
205
|
+
```yaml
|
|
206
|
+
lenient: true
|
|
207
|
+
|
|
208
|
+
documents:
|
|
209
|
+
- source: https://api.example.com/openapi.json
|
|
210
|
+
output: ./client
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
otter generate --lenient
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
**Vendor extensions are always preserved.** OpenAPI specification extensions
|
|
218
|
+
(`x-*`) are kept in both strict and lenient mode. The only exception is the
|
|
219
|
+
type-discriminated security-scheme objects (`apiKey`, `http`, `oauth2`,
|
|
220
|
+
`openIdConnect`), which still reject unknown keys so their variant stays
|
|
221
|
+
unambiguous.
|
|
222
|
+
|
|
206
223
|
---
|
|
207
224
|
|
|
208
225
|
## 📦 Module Splitting
|
|
@@ -475,14 +492,14 @@ pagination:
|
|
|
475
492
|
### Usage
|
|
476
493
|
|
|
477
494
|
```python
|
|
478
|
-
from client import list_users_iter,
|
|
495
|
+
from client import list_users_iter, async_list_users_iter
|
|
479
496
|
|
|
480
497
|
# Iterate all users (handles pagination automatically)
|
|
481
498
|
for user in list_users_iter():
|
|
482
499
|
print(user.name)
|
|
483
500
|
|
|
484
501
|
# Async variant
|
|
485
|
-
async for user in
|
|
502
|
+
async for user in async_list_users_iter():
|
|
486
503
|
print(user.name)
|
|
487
504
|
```
|
|
488
505
|
|
|
@@ -509,7 +526,7 @@ documents:
|
|
|
509
526
|
| Original | Pandas | Polars |
|
|
510
527
|
|----------|--------|--------|
|
|
511
528
|
| `get_users()` | `get_users_df()` | `get_users_pl()` |
|
|
512
|
-
| `
|
|
529
|
+
| `async_get_users()` | `async_get_users_df()` | `async_get_users_pl()` |
|
|
513
530
|
|
|
514
531
|
### Usage
|
|
515
532
|
|
|
@@ -679,8 +696,8 @@ response_unwrap:
|
|
|
679
696
|
```python
|
|
680
697
|
from client import get_user, create_user, list_orders
|
|
681
698
|
|
|
682
|
-
# Async versions are prefixed with '
|
|
683
|
-
from client import
|
|
699
|
+
# Async versions are prefixed with 'async_'
|
|
700
|
+
from client import async_get_user, async_create_user, async_list_orders
|
|
684
701
|
|
|
685
702
|
# Sync
|
|
686
703
|
user = get_user(user_id=123)
|
|
@@ -689,7 +706,7 @@ user = get_user(user_id=123)
|
|
|
689
706
|
import asyncio
|
|
690
707
|
|
|
691
708
|
async def main():
|
|
692
|
-
user = await
|
|
709
|
+
user = await async_get_user(user_id=123)
|
|
693
710
|
|
|
694
711
|
asyncio.run(main())
|
|
695
712
|
```
|
|
@@ -715,7 +732,7 @@ client = Client(
|
|
|
715
732
|
user = client.get_user(user_id=123)
|
|
716
733
|
|
|
717
734
|
async def main():
|
|
718
|
-
user = await client.
|
|
735
|
+
user = await client.async_get_user(user_id=123)
|
|
719
736
|
```
|
|
720
737
|
|
|
721
738
|
### Working with Models
|
|
@@ -739,6 +756,9 @@ otter generate
|
|
|
739
756
|
# Generate from specific config file
|
|
740
757
|
otter generate -c my-config.yml
|
|
741
758
|
|
|
759
|
+
# Tolerate malformed specs (drop unknown/invalid fields with a warning)
|
|
760
|
+
otter generate --lenient
|
|
761
|
+
|
|
742
762
|
# Initialize a new config file
|
|
743
763
|
otter init
|
|
744
764
|
|
|
@@ -15,12 +15,12 @@ Quick Start:
|
|
|
15
15
|
>>> codegen.generate()
|
|
16
16
|
|
|
17
17
|
CLI Usage:
|
|
18
|
-
$
|
|
19
|
-
$
|
|
20
|
-
$
|
|
18
|
+
$ otter generate --source ./api.yaml --output ./client
|
|
19
|
+
$ otter init # Create a configuration file interactively
|
|
20
|
+
$ otter validate ./api.yaml # Validate an OpenAPI spec
|
|
21
21
|
|
|
22
22
|
For more information, see the documentation at:
|
|
23
|
-
https://github.com/
|
|
23
|
+
https://github.com/danplischke/otter
|
|
24
24
|
"""
|
|
25
25
|
|
|
26
26
|
from otterapi.codegen.codegen import Codegen
|
|
@@ -8,7 +8,7 @@ import json
|
|
|
8
8
|
import logging
|
|
9
9
|
import traceback
|
|
10
10
|
from pathlib import Path
|
|
11
|
-
from typing import Annotated
|
|
11
|
+
from typing import Annotated, Any
|
|
12
12
|
|
|
13
13
|
import typer
|
|
14
14
|
import yaml
|
|
@@ -32,14 +32,14 @@ error_console = Console(stderr=True)
|
|
|
32
32
|
def _commented_optional_sections() -> str:
|
|
33
33
|
"""Return a YAML block of commented-out optional config sections.
|
|
34
34
|
|
|
35
|
-
Appended to ``otter.yml`` by ``
|
|
35
|
+
Appended to ``otter.yml`` by ``otter init`` so users discover the
|
|
36
36
|
pagination / dataframe / export / module_split / response_unwrap
|
|
37
37
|
knobs by editing rather than by hunting through the README.
|
|
38
38
|
"""
|
|
39
39
|
return """
|
|
40
40
|
# ----------------------------------------------------------------------
|
|
41
41
|
# Optional sections -- uncomment to enable. See the README for details:
|
|
42
|
-
# https://github.com/danplischke/
|
|
42
|
+
# https://github.com/danplischke/otter
|
|
43
43
|
# ----------------------------------------------------------------------
|
|
44
44
|
|
|
45
45
|
# documents:
|
|
@@ -155,7 +155,7 @@ def _resolve_codegen_config(
|
|
|
155
155
|
except FileNotFoundError as e:
|
|
156
156
|
error_console.print(f'[red]Error:[/red] {e}')
|
|
157
157
|
error_console.print(
|
|
158
|
-
'\n[dim]Hint: Run [bold]
|
|
158
|
+
'\n[dim]Hint: Run [bold]otter init[/bold] to create a configuration file,[/dim]'
|
|
159
159
|
)
|
|
160
160
|
error_console.print(
|
|
161
161
|
'[dim]or use [bold]--source[/bold] and [bold]--output[/bold] options.[/dim]'
|
|
@@ -170,6 +170,7 @@ def _generate_document(
|
|
|
170
170
|
validate_output: bool = True,
|
|
171
171
|
generate_endpoints: bool = True,
|
|
172
172
|
create_py_typed: bool = True,
|
|
173
|
+
lenient: bool = False,
|
|
173
174
|
) -> None:
|
|
174
175
|
"""Run code generation for a single document, with a progress spinner."""
|
|
175
176
|
with Progress(
|
|
@@ -188,6 +189,7 @@ def _generate_document(
|
|
|
188
189
|
validate_output=validate_output,
|
|
189
190
|
generate_endpoints=generate_endpoints,
|
|
190
191
|
create_py_typed=create_py_typed,
|
|
192
|
+
lenient=lenient,
|
|
191
193
|
)
|
|
192
194
|
generated_files = codegen.generate()
|
|
193
195
|
progress.update(
|
|
@@ -222,6 +224,16 @@ def generate(
|
|
|
222
224
|
bool, typer.Option('--verbose', '-v', help='Enable verbose output')
|
|
223
225
|
] = False,
|
|
224
226
|
debug: Annotated[bool, typer.Option('--debug', help='Enable debug output')] = False,
|
|
227
|
+
lenient: Annotated[
|
|
228
|
+
bool,
|
|
229
|
+
typer.Option(
|
|
230
|
+
'--lenient',
|
|
231
|
+
help=(
|
|
232
|
+
'Drop unrecognized, structurally-invalid fields from the spec '
|
|
233
|
+
'instead of failing validation (with a warning)'
|
|
234
|
+
),
|
|
235
|
+
),
|
|
236
|
+
] = False,
|
|
225
237
|
) -> None:
|
|
226
238
|
"""Generate Python client code from OpenAPI specifications.
|
|
227
239
|
|
|
@@ -229,11 +241,12 @@ def generate(
|
|
|
229
241
|
directly via command-line options.
|
|
230
242
|
|
|
231
243
|
Examples:
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
244
|
+
otter generate
|
|
245
|
+
otter generate --config my-config.yaml
|
|
246
|
+
otter generate -c config.json
|
|
247
|
+
otter generate --source https://api.example.com/openapi.json --output ./client
|
|
248
|
+
otter generate -s ./api.yaml -o ./generated
|
|
249
|
+
otter generate -s ./api.yaml -o ./generated --lenient
|
|
237
250
|
"""
|
|
238
251
|
setup_logging(verbose, debug)
|
|
239
252
|
|
|
@@ -247,6 +260,7 @@ def generate(
|
|
|
247
260
|
validate_output=codegen_config.validate_output,
|
|
248
261
|
generate_endpoints=codegen_config.generate_endpoints,
|
|
249
262
|
create_py_typed=codegen_config.create_py_typed,
|
|
263
|
+
lenient=lenient or codegen_config.lenient,
|
|
250
264
|
)
|
|
251
265
|
|
|
252
266
|
console.print('\n[green]✓[/green] Code generation completed!')
|
|
@@ -278,9 +292,9 @@ def init(
|
|
|
278
292
|
with all the necessary settings.
|
|
279
293
|
|
|
280
294
|
Examples:
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
295
|
+
otter init
|
|
296
|
+
otter init otter.yaml
|
|
297
|
+
otter init config.json --force
|
|
284
298
|
"""
|
|
285
299
|
config_path = Path(path)
|
|
286
300
|
|
|
@@ -333,9 +347,8 @@ def init(
|
|
|
333
347
|
content = json.dumps(config_data, indent=2)
|
|
334
348
|
else:
|
|
335
349
|
content = yaml.dump(config_data, default_flow_style=False, sort_keys=False)
|
|
336
|
-
#
|
|
337
|
-
#
|
|
338
|
-
# cross-referencing the README.
|
|
350
|
+
# Append commented-out scaffolds for the optional sections so users can
|
|
351
|
+
# discover them by editing instead of cross-referencing the README.
|
|
339
352
|
content += _commented_optional_sections()
|
|
340
353
|
|
|
341
354
|
config_path.write_text(content)
|
|
@@ -346,7 +359,7 @@ def init(
|
|
|
346
359
|
console.print(syntax)
|
|
347
360
|
|
|
348
361
|
console.print(
|
|
349
|
-
f'\n[dim]Run [bold]
|
|
362
|
+
f'\n[dim]Run [bold]otter generate -c {path}[/bold] to generate code.[/dim]'
|
|
350
363
|
)
|
|
351
364
|
|
|
352
365
|
|
|
@@ -363,9 +376,9 @@ def _count_operations(paths) -> int:
|
|
|
363
376
|
return operations
|
|
364
377
|
|
|
365
378
|
|
|
366
|
-
def _summarize_schema(schema) -> dict[str,
|
|
379
|
+
def _summarize_schema(schema) -> dict[str, Any]:
|
|
367
380
|
"""Collect descriptive info (title, counts, ...) about a loaded schema."""
|
|
368
|
-
info: dict[str,
|
|
381
|
+
info: dict[str, Any] = {}
|
|
369
382
|
|
|
370
383
|
if schema.info:
|
|
371
384
|
info['title'] = schema.info.title
|
|
@@ -423,7 +436,7 @@ def _load_schema_for_validation(source: str, progress, task):
|
|
|
423
436
|
|
|
424
437
|
|
|
425
438
|
def _print_validation_report(
|
|
426
|
-
source: str, info: dict[str,
|
|
439
|
+
source: str, info: dict[str, Any], warnings: list[str], verbose: bool
|
|
427
440
|
) -> None:
|
|
428
441
|
"""Print the schema summary table and any operationId warnings."""
|
|
429
442
|
console.print(f'\n[green]✓[/green] Schema is valid: {source}\n')
|
|
@@ -459,9 +472,9 @@ def validate(
|
|
|
459
472
|
generating any code, reporting any errors or warnings found.
|
|
460
473
|
|
|
461
474
|
Examples:
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
475
|
+
otter validate ./api.yaml
|
|
476
|
+
otter validate https://api.example.com/openapi.json
|
|
477
|
+
otter validate ./api.yaml --verbose
|
|
465
478
|
"""
|
|
466
479
|
with Progress(
|
|
467
480
|
SpinnerColumn(),
|
|
@@ -10,8 +10,7 @@ requires touching every codegen file.
|
|
|
10
10
|
that exposes the *intent* of what codegen wants from the parser
|
|
11
11
|
("paths()", "components_schema(name)", "info_title()") rather than raw
|
|
12
12
|
attribute access. New call sites in codegen should reach for the adapter
|
|
13
|
-
first; existing direct uses can migrate incrementally as touched
|
|
14
|
-
and tracked in issue #3, item 10).
|
|
13
|
+
first; existing direct uses can migrate incrementally as touched.
|
|
15
14
|
|
|
16
15
|
Keeping this minimal on purpose: the goal is to *establish the seam*, not
|
|
17
16
|
to wholesale-translate every operation. Each method lands as a real
|
|
@@ -6,7 +6,8 @@ and utilities for collecting and organizing imports during code generation.
|
|
|
6
6
|
|
|
7
7
|
import ast
|
|
8
8
|
import sys
|
|
9
|
-
from collections.abc import Iterable
|
|
9
|
+
from collections.abc import Iterable, Sequence
|
|
10
|
+
from typing import cast
|
|
10
11
|
|
|
11
12
|
__all__ = [
|
|
12
13
|
# AST helpers
|
|
@@ -83,7 +84,12 @@ def _ann_assign(
|
|
|
83
84
|
"""Build ``target: annotation = value``."""
|
|
84
85
|
if isinstance(target, ast.Name):
|
|
85
86
|
target = ast.Name(id=target.id, ctx=ast.Store())
|
|
86
|
-
return ast.AnnAssign(
|
|
87
|
+
return ast.AnnAssign(
|
|
88
|
+
target=cast('ast.Name | ast.Attribute | ast.Subscript', target),
|
|
89
|
+
annotation=annotation,
|
|
90
|
+
value=value,
|
|
91
|
+
simple=1,
|
|
92
|
+
)
|
|
87
93
|
|
|
88
94
|
|
|
89
95
|
def _assign(target: ast.expr, value: ast.expr) -> ast.Assign:
|
|
@@ -124,9 +130,9 @@ def _func(
|
|
|
124
130
|
args: list[ast.arg],
|
|
125
131
|
body: list[ast.stmt],
|
|
126
132
|
returns: ast.expr | None = None,
|
|
127
|
-
kwargs: ast.arg = None,
|
|
128
|
-
kwonlyargs:
|
|
129
|
-
kw_defaults:
|
|
133
|
+
kwargs: ast.arg | None = None,
|
|
134
|
+
kwonlyargs: Sequence[ast.arg] | None = None,
|
|
135
|
+
kw_defaults: Sequence[ast.expr | None] | None = None,
|
|
130
136
|
) -> ast.FunctionDef:
|
|
131
137
|
return ast.FunctionDef(
|
|
132
138
|
name=name,
|
|
@@ -134,8 +140,8 @@ def _func(
|
|
|
134
140
|
posonlyargs=[],
|
|
135
141
|
args=args,
|
|
136
142
|
kwarg=kwargs,
|
|
137
|
-
kwonlyargs=kwonlyargs
|
|
138
|
-
kw_defaults=kw_defaults
|
|
143
|
+
kwonlyargs=list(kwonlyargs) if kwonlyargs else [],
|
|
144
|
+
kw_defaults=list(kw_defaults) if kw_defaults else [],
|
|
139
145
|
defaults=[],
|
|
140
146
|
),
|
|
141
147
|
body=body,
|
|
@@ -149,9 +155,9 @@ def _async_func(
|
|
|
149
155
|
args: list[ast.arg],
|
|
150
156
|
body: list[ast.stmt],
|
|
151
157
|
returns: ast.expr | None = None,
|
|
152
|
-
kwargs: ast.arg = None,
|
|
153
|
-
kwonlyargs:
|
|
154
|
-
kw_defaults:
|
|
158
|
+
kwargs: ast.arg | None = None,
|
|
159
|
+
kwonlyargs: Sequence[ast.arg] | None = None,
|
|
160
|
+
kw_defaults: Sequence[ast.expr | None] | None = None,
|
|
155
161
|
) -> ast.AsyncFunctionDef:
|
|
156
162
|
return ast.AsyncFunctionDef(
|
|
157
163
|
name=name,
|
|
@@ -159,8 +165,8 @@ def _async_func(
|
|
|
159
165
|
posonlyargs=[],
|
|
160
166
|
args=args,
|
|
161
167
|
kwarg=kwargs,
|
|
162
|
-
kwonlyargs=kwonlyargs
|
|
163
|
-
kw_defaults=kw_defaults
|
|
168
|
+
kwonlyargs=list(kwonlyargs) if kwonlyargs else [],
|
|
169
|
+
kw_defaults=list(kw_defaults) if kw_defaults else [],
|
|
164
170
|
defaults=[],
|
|
165
171
|
),
|
|
166
172
|
body=body,
|