Skip to content

Commit f56806d

Browse files
committed
Update configuration.mdx based on issue #266
1 parent 2b6d877 commit f56806d

File tree

1 file changed

+66
-45
lines changed

1 file changed

+66
-45
lines changed

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

Lines changed: 66 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ groups:
2121
## SDK Configuration Options
2222
2323
<ParamField path="additional_init_exports" type="array" default="null" required={false} toc={true}>
24+
Additional exports to include in the package's __init__.py file.
2425
</ParamField>
2526
2627
<ParamField path="default_bytes_stream_chunk_size" type="number" default="null" required={false} toc={true}>
2728
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>):`
2829
</ParamField>
2930

3031
<ParamField path="exclude_types_from_init_exports" type="bool" default="false" required={false} toc={true}>
32+
Whether to exclude type definitions from being exported in the package's __init__.py file.
3133
</ParamField>
3234

3335
<ParamField path="extra_dependencies" type="object" default="{}" required={false} toc={true}>
@@ -40,98 +42,83 @@ groups:
4042
</ParamField>
4143

4244
<ParamField path="extra_dev_dependencies" type="object" default="{}" required={false} toc={true}>
45+
Additional development dependencies to include in the generated package.
4346
</ParamField>
4447

4548
<ParamField path="extras" type="object" default="{}" required={false} toc={true}>
49+
Optional dependency groups that can be installed with the package.
4650
</ParamField>
4751

4852
<ParamField path="flat_layout" type="bool" default="false" required={false} toc={true}>
53+
Whether to generate a flat file structure instead of nested directories.
4954
</ParamField>
5055

5156
<ParamField path="follow_redirects_by_default" type="bool" default="true" required={false} toc={true}>
5257
Whether to follow redirects by default in HTTP requests.
5358
</ParamField>
5459

5560
<ParamField path="improved_imports" type="bool" default="true" required={false} toc={true}>
56-
Feature flag that improves imports in the Python SDK by removing nested `resources` directory
61+
Feature flag that improves imports in the Python SDK by removing nested `resources` directory.
5762
</ParamField>
5863

5964
<ParamField path="include_legacy_wire_tests" type="bool" default="false" required={false} toc={true}>
60-
Whether or not to include legacy wire tests in the generated SDK
65+
Whether or not to include legacy wire tests in the generated SDK.
6166
</ParamField>
6267

6368
<ParamField path="include_union_utils" type="bool" default="false" required={false} toc={true}>
69+
When enabled, generates utility functions for working with union types.
6470
</ParamField>
6571

6672
<ParamField path="inline_path_params" type="bool" default="false" required={false} toc={true}>
67-
If true, treats path parameters as named parameters in endpoint functions.
73+
If true, treats path parameters as named parameters in endpoint functions rather than using a request object.
6874
</ParamField>
6975

7076
<ParamField path="inline_request_params" type="bool" default="true" required={false} toc={true}>
7177
Feature flag that removes the usage of request objects, and instead uses parameters in function signatures where possible.
7278
</ParamField>
7379

7480
<ParamField path="package_name" type="string" default="null" required={false} toc={true}>
75-
76-
Specifies the Python package name that users will import your generated client
77-
from.
81+
Specifies the Python package name that users will import your generated client from.
7882

79-
For example, setting `package_name: "my_custom_package"` enables users to use
80-
`my_custom_package import Client` to import your client:
83+
For example, setting `package_name: "my_custom_package"` enables users to use `my_custom_package import Client` to import your client:
8184

82-
```yaml {7-10}
83-
default-group: local
84-
groups:
85-
local:
86-
generators:
87-
- name: fernapi/fern-python
88-
version: 0.7.1
89-
config:
90-
package_name: "my_custom_package"
91-
```
85+
```yaml
86+
config:
87+
package_name: "my_custom_package"
88+
```
9289
</ParamField>
9390

9491
<ParamField path="pydantic_config" type="SdkPydanticModelCustomConfig" default="SdkPydanticModelCustomConfig()" required={false} toc={true}>
92+
Configuration options for Pydantic model generation.
9593
</ParamField>
9694

9795
<ParamField path="pydantic_config.include_union_utils" type="bool" default="false" required={false} toc={true}>
98-
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:
96+
When enabled, generates a Pydantic `__root__` class containing utilities to visit unions. For example:
9997

100-
```
101-
types:
102-
Shape:
103-
union:
104-
circle: Circle
105-
triangle: Triangle
106-
```
107-
you will get a generated `Shape` class that has a factory and visitor:
10898
```python
10999
# Use a factory to instantiate the union
110100
Shape.factory.circle(Circle(...))
111101
112102
# Visit every case in the union
113103
shape = get_shape()
114104
shape.visit(
115-
circle: lambda circle: do_something_with_circle(circle),
116-
triangle: lambda triangle: do_something_with_triangle(triangle),
105+
circle=lambda circle: do_something_with_circle(circle),
106+
triangle=lambda triangle: do_something_with_triangle(triangle),
117107
)
118108
```
119-
120-
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.
121109
</ParamField>
122110

123111
<ParamField path="pydantic_config.version" type="'v1' | 'v2' | 'both' | 'v1_on_v2'" default="both" required={false} toc={true}>
124-
By default, the generator generates pydantic models that are v1 and v2 compatible. However you can override them to:
112+
Controls Pydantic version compatibility:
125113
- `v1`: strictly use Pydantic v1
126-
- `v2`: strictly use Pydantic v2
114+
- `v2`: strictly use Pydantic v2
127115
- `both`: maintain compatibility with both versions
128116
- `v1_on_v2`: use Pydantic v1 compatibility layer on v2
129-
130-
Example:
117+
131118
```yaml
132119
config:
133120
pydantic_config:
134-
version: v1 # or v2 or "both"
121+
version: v2
135122
```
136123
</ParamField>
137124

@@ -140,20 +127,23 @@ groups:
140127
</ParamField>
141128

142129
<ParamField path="pyproject_toml" type="string" default="null" required={false} toc={true}>
130+
Custom pyproject.toml contents to include in the generated package.
143131
</ParamField>
144132

145133
<ParamField path="should_generate_websocket_clients" type="bool" default="false" required={false} toc={true}>
146134
Feature flag that enables generation of Python websocket clients.
147135
</ParamField>
148136

149137
<ParamField path="skip_formatting" type="bool" default="false" required={false} toc={true}>
138+
Whether to skip code formatting on the generated files.
150139
</ParamField>
151140

152141
<ParamField path="timeout_in_seconds" type="number | 'infinity'" default="60" required={false} toc={true}>
153142
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.
154143
</ParamField>
155144

156145
<ParamField path="use_api_name_in_package" type="bool" default="false" required={false} toc={true}>
146+
Whether to include the API name in the generated package name.
157147
</ParamField>
158148

159149
<ParamField path="use_inheritance_for_extended_models" type="bool" default="true" required={false} toc={true}>
@@ -168,17 +158,48 @@ groups:
168158
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.
169159
</ParamField>
170160

161+
### Extension Headers
162+
163+
The Python generator supports extension headers through the `x-fern-sdk-variables` configuration in your OpenAPI spec. This allows you to define variables that will be included in the client configuration and injected into API paths.
164+
165+
For example, to define a project ID variable that will be included in all paths:
166+
167+
```yaml
168+
x-fern-sdk-variables:
169+
project_id:
170+
type: string
171+
description: "The ID of the project"
172+
pattern: "^proj_[a-zA-Z0-9]+$"
173+
```
174+
175+
This variable can then be referenced in your paths:
176+
177+
```yaml
178+
paths:
179+
/v1/connect/{project_id}/accounts:
180+
parameters:
181+
- name: project_id
182+
in: path
183+
required: true
184+
schema:
185+
type: string
186+
x-fern-sdk-variable: project_id
187+
```
188+
189+
The generated client will include this variable in its configuration and automatically inject it into request paths.
190+
171191
### client
172-
Configuration for the generated client class and file structure.
173192

174-
```yaml
175-
config:
176-
client:
177-
filename: "my_client.py"
178-
class_name: "MyClient"
179-
exported_filename: "my_client.py"
180-
exported_class_name: "MyClient"
181-
```
193+
Configuration for the generated client class and file structure.
194+
195+
```yaml
196+
config:
197+
client:
198+
filename: "my_client.py"
199+
class_name: "MyClient"
200+
exported_filename: "my_client.py"
201+
exported_class_name: "MyClient"
202+
```
182203

183204
<ParamField path="filename" type="string" default="client.py" required={false} toc={true}>
184205
The filename for the generated client file.

0 commit comments

Comments
 (0)