Python Configuration

You can customize the behavior of the Python SDK generator in generators.yml:

1default-group: local
2groups:
3 local:
4 generators:
5 - name: fernapi/fern-python
6 version: 0.7.1
7 config:
8 client:
9 class_name: "YourClient"

SDK Configuration Options

additional_init_exports
arrayDefaults to null
client
ClientConfigurationDefaults to ClientConfiguration()
default_bytes_stream_chunk_size
numberDefaults to null

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>):

exclude_types_from_init_exports
boolDefaults to false
extra_dependencies
objectDefaults to {}

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:

config:
extra_dependencies:
boto3: 1.28.15
extra_dev_dependencies
objectDefaults to {}
extras
objectDefaults to {}
flat_layout
boolDefaults to false
follow_redirects_by_default
boolDefaults to true

Whether to follow redirects by default in HTTP requests.

improved_imports
boolDefaults to true

Feature flag that improves imports in the Python SDK by removing nested resources directory

include_legacy_wire_tests
boolDefaults to false

Whether or not to include legacy wire tests in the generated SDK

include_union_utils
boolDefaults to false
inline_path_params
boolDefaults to false

If true, treats path parameters as named parameters in endpoint functions.

inline_request_params
boolDefaults to true

Feature flag that removes the usage of request objects, and instead uses parameters in function signatures where possible.

package_name
stringDefaults to null
pydantic_config
SdkPydanticModelCustomConfigDefaults to SdkPydanticModelCustomConfig()
pydantic_config.include_union_utils
boolDefaults to false

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:

types:
Shape:
union:
circle: Circle
triangle: Triangle

you will get a generated Shape class that has a factory and visitor:

1# Use a factory to instantiate the union
2Shape.factory.circle(Circle(...))
3
4# Visit every case in the union
5shape = get_shape()
6shape.visit(
7 circle: lambda circle: do_something_with_circle(circle),
8 triangle: lambda triangle: do_something_with_triangle(triangle),
9)

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.

pydantic_config.version
'v1' | 'v2' | 'both' | 'v1_on_v2'Defaults to both

By default, the generator generates pydantic models that are v1 and v2 compatible. However you can override them to:

  • v1: strictly use Pydantic v1
  • v2: strictly use Pydantic v2
  • both: maintain compatibility with both versions
  • v1_on_v2: use Pydantic v1 compatibility layer on v2

Example:

1config:
2 pydantic_config:
3 version: v1 # or v2 or "both"
pyproject_python_version
stringDefaults to ^3.8
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.
pyproject_toml
stringDefaults to null
should_generate_websocket_clients
boolDefaults to false

Feature flag that enables generation of Python websocket clients.

skip_formatting
boolDefaults to false
timeout_in_seconds
number | 'infinity'Defaults to 60

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.

use_api_name_in_package
boolDefaults to false
use_inheritance_for_extended_models
boolDefaults to true

Whether to generate Pydantic models that implement inheritance when a model utilizes the Fern extends keyword.

use_typeddict_requests
boolDefaults to false

Whether or not to generate TypedDicts instead of Pydantic Models for request objects.

use_typeddict_requests_for_file_upload
boolDefaults to false

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.