Skip to content

Commit f728e21

Browse files
authored
Add documentation for Python configuration options (#17)
1 parent 03bcb7e commit f728e21

File tree

1 file changed

+148
-2
lines changed

1 file changed

+148
-2
lines changed

fern/products/sdks/overview/python/configuration.mdx

Lines changed: 148 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,152 @@ title: Python Configuration
33
description: Configuration options for the Fern Python SDK.
44
---
55

6-
# Python Configuration
6+
You can customize the behavior of the Python SDK generator in `generators.yml`:
77

8-
Discover how to configure the Fern Python SDK for your project.
8+
```yaml {7-8}
9+
default-group: local
10+
groups:
11+
local:
12+
generators:
13+
- name: fernapi/fern-python
14+
version: 0.7.1
15+
config:
16+
client:
17+
class_name: `YourClient`
18+
```
19+
20+
## SDK Configuration Options
21+
22+
<ParamField path="extra_dependencies" type="object" default="{}" required={false}>
23+
If you want to add custom dependencies to your generated SDK, you can specify them using this configuration. For example, to add a dependency on boto3, your config would look like:
24+
```
25+
config:
26+
extra_dependencies:
27+
boto3: 1.28.15
28+
```
29+
</ParamField>
30+
31+
<ParamField path="extra_dev_dependencies" type="object" default="{}" required={false}>
32+
</ParamField>
33+
34+
<ParamField path="extras" type="object" default="{}" required={false}>
35+
</ParamField>
36+
37+
<ParamField path="skip_formatting" type="bool" default="false" required={false}>
38+
</ParamField>
39+
40+
<ParamField path="client" type="ClientConfiguration" default="ClientConfiguration()" required={false}>
41+
</ParamField>
42+
43+
<ParamField path="include_union_utils" type="bool" default="false" required={false}>
44+
</ParamField>
45+
46+
<ParamField path="use_api_name_in_package" type="bool" default="false" required={false}>
47+
</ParamField>
48+
49+
<ParamField path="package_name" type="string" default="null" required={false}>
50+
</ParamField>
51+
52+
<ParamField path="timeout_in_seconds" type="number | 'infinity'" default="60" required={false}>
53+
By default, the generator generates a client that times out after 60 seconds. You can customize this value by providing a different number or setting to `infinity` to get rid of timeouts.
54+
</ParamField>
55+
56+
<ParamField path="flat_layout" type="bool" default="false" required={false}>
57+
</ParamField>
58+
59+
<ParamField path="pydantic_config" type="SdkPydanticModelCustomConfig" default="SdkPydanticModelCustomConfig()" required={false}>
60+
</ParamField>
61+
62+
<ParamField path="pydantic_config.include_union_utils" type="bool" default="false" required={false}>
63+
When enabled, the generator will output a Pydantic `__root__` class that will contain utilities to visit the union. For example, for the following union type:
64+
65+
```
66+
types:
67+
Shape:
68+
union:
69+
circle: Circle
70+
triangle: Triangle
71+
```
72+
you will get a generated `Shape` class that has a factory and visitor:
73+
```python
74+
# Use a factory to instantiate the union
75+
Shape.factory.circle(Circle(...))
76+
77+
# Visit every case in the union
78+
shape = get_shape()
79+
shape.visit(
80+
circle: lambda circle: do_something_with_circle(circle),
81+
triangle: lambda triangle: do_something_with_triangle(triangle),
82+
)
83+
```
84+
85+
When enabled, the python generator will not run Black formatting in the generated code. Black is slow so this can potentially speed up code generation quite a bit.
86+
</ParamField>
87+
88+
<ParamField path="pydantic_config.version" type="'v1' | 'v2' | 'both' | 'v1_on_v2'" default="both" required={false}>
89+
By default, the generator generates pydantic models that are v1 and v2 compatible. However you can override them to:
90+
- `v1`: strictly use Pydantic v1
91+
- `v2`: strictly use Pydantic v2
92+
- `both`: maintain compatibility with both versions
93+
- `v1_on_v2`: use Pydantic v1 compatibility layer on v2
94+
95+
Example:
96+
```yaml
97+
config:
98+
pydantic_config:
99+
version: v1 # or v2 or "both"
100+
```
101+
</ParamField>
102+
103+
<ParamField path="additional_init_exports" type="array" default="null" required={false}>
104+
</ParamField>
105+
106+
<ParamField path="exclude_types_from_init_exports" type="bool" default="false" required={false}>
107+
</ParamField>
108+
109+
<ParamField path="improved_imports" type="bool" default="true" required={false}>
110+
Feature flag that improves imports in the Python SDK by removing nested `resources` directory
111+
</ParamField>
112+
113+
<ParamField path="follow_redirects_by_default" type="bool" default="true" required={false}>
114+
Whether to follow redirects by default in HTTP requests.
115+
</ParamField>
116+
117+
<ParamField path="inline_request_params" type="bool" default="true" required={false}>
118+
Feature flag that removes the usage of request objects, and instead uses parameters in function signatures where possible.
119+
</ParamField>
120+
121+
<ParamField path="inline_path_params" type="bool" default="false" required={false}>
122+
If true, treats path parameters as named parameters in endpoint functions.
123+
</ParamField>
124+
125+
<ParamField path="should_generate_websocket_clients" type="bool" default="false" required={false}>
126+
Feature flag that enables generation of Python websocket clients.
127+
</ParamField>
128+
129+
<ParamField path="pyproject_python_version" type="string" default="^3.8" required={false}>
130+
<Warning>This changes your declared python dependency, which is not meant to be done often if at all. This is a last resort if any dependencies force you to change your version requirements.</Warning>
131+
</ParamField>
132+
133+
<ParamField path="use_typeddict_requests" type="bool" default="false" required={false}>
134+
Whether or not to generate `TypedDicts` instead of Pydantic Models for request objects.
135+
</ParamField>
136+
137+
<ParamField path="use_typeddict_requests_for_file_upload" type="bool" default="false" required={false}>
138+
Whether or not to generate TypedDicts instead of Pydantic Models for file upload request objects. Note that this flag was only introduced due to an oversight in the `use_typeddict_requests` flag implementation; it should be removed in the future.
139+
</ParamField>
140+
141+
<ParamField path="use_inheritance_for_extended_models" type="bool" default="true" required={false}>
142+
Whether to generate Pydantic models that implement inheritance when a model utilizes the Fern `extends` keyword.
143+
</ParamField>
144+
145+
<ParamField path="pyproject_toml" type="string" default="null" required={false}>
146+
</ParamField>
147+
148+
<ParamField path="default_bytes_stream_chunk_size" type="number" default="null" required={false}>
149+
The chunk size to use (if any) when processing a response bytes stream within `iter_bytes` or `aiter_bytes` results in: `for chunk in response.iter_bytes(chunk_size=<default_bytes_stream_chunk_size>):`
150+
</ParamField>
151+
152+
<ParamField path="include_legacy_wire_tests" type="bool" default="false" required={false}>
153+
Whether or not to include legacy wire tests in the generated SDK
154+
</ParamField>

0 commit comments

Comments
 (0)