Python Configuration
You can customize the behavior of the Python SDK generator in generators.yml
:
SDK Configuration Options
additional_init_exports
Additional modules or classes to export from the package’s __init__.py
file. This allows you to customize what’s available when users import your package.
Each object should specify which file to import from and what to import:
This enables users to access your custom functions directly:
The module path to import from, using Python dot notation. Omit the .py
extension and replace path separators with dots.
For example, if you want to import from the file core/oauth_flow.py
, specify that as - from: core.oauth_flow
.
List of class names, function names, or other objects to import from the specified file.
default_bytes_stream_chunk_size
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
When enabled, excludes type definitions from being exported in the package’s __init__.py
file, reducing the public API surface.
extra_dependencies
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:
extra_dev_dependencies
Specify additional development dependencies to include in the generated SDK’s setup configuration. These are dependencies used for development and testing but not required by end users.
extras
Define optional dependency groups that users can install with your package using pip extras (e.g., pip install your-package[extra-name]
).
flat_layout
When enabled, generates a flatter package structure by reducing nested directories and modules.
follow_redirects_by_default
Whether to follow redirects by default in HTTP requests.
improved_imports
Feature flag that improves imports in the Python SDK by removing nested resources
directory
include_legacy_wire_tests
Whether or not to include legacy wire tests in the generated SDK
include_union_utils
When enabled, generates utility methods for working with union types, including factory methods and visitor patterns.
inline_path_params
If true, treats path parameters as named parameters in endpoint functions.
inline_request_params
Feature flag that removes the usage of request objects, and instead uses parameters in function signatures where possible.
package_name
Specifies the Python package name that users will import your generated client from.
For example, setting package_name: "my_custom_package"
enables users to use
my_custom_package import Client
to import your client:
pyproject_python_version
pyproject_toml
Path to a custom pyproject.toml
template file to use instead of the default generated one.
should_generate_websocket_clients
Feature flag that enables generation of Python websocket clients.
skip_formatting
When enabled, skips code formatting (like black) on the generated Python code.
timeout_in_seconds
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
When enabled, includes the API name as part of the package structure and naming.
use_inheritance_for_extended_models
Whether to generate Pydantic models that implement inheritance when a model utilizes the Fern extends
keyword.
use_typeddict_requests
Whether or not to generate TypedDicts
instead of Pydantic Models for request objects.
use_typeddict_requests_for_file_upload
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.
client
Configuration for the generated client class and file structure.
filename
The filename for the generated client file.
class_name
The name of the generated client class.
exported_filename
The filename of the exported client which will be used in code snippets.
exported_class_name
The name of the exported client class that will be used in code snippets.
pydantic_config
Configure Pydantic model generation settings for your Python SDK.
enum_type
The type of enums to use in the generated models:
literals
: Use Python Literal types, e.g.MyEnum = Literal["foo", "bar"]
forward_compatible_python_enums
: Use Python Enum classes, with aMyEnum._UNKNOWN
member for forward compatibility.MyEnum._UNKNOWN.value
contains the raw unrecognized value.python_enums
: Your vanilla Python enum class, with the members defined within your API.
extra_fields
How to handle extra fields not defined in the model schema.
frozen
Whether Pydantic models should be frozen (immutable after creation).
include_union_utils
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:
you will get a generated Shape
class that has a factory and visitor:
include_validators
Include custom validators in generated Pydantic models.
orm_mode
Enable ORM mode for Pydantic models to work with ORMs like SQLAlchemy.
package_name
Custom package name for the generated models.
require_optional_fields
Whether optional fields must be explicitly provided (cannot be omitted).
skip_formatting
Skip code formatting for generated Pydantic models.
skip_validation
When enabled, disables Pydantic validation for API responses. This ensures that Pydantic does not immediately fail if the model being returned from an API does not exactly match the Pydantic model.
This is meant to add flexibility should your SDK fall behind your API, but should be used sparingly, as the type-hinting for users will still reflect the Pydantic model exactly.
smart_union
Enable smart union handling in Pydantic models for better type discrimination.
union_naming
Control union naming strategy. If you are dealing with discriminated union members that already have the discriminant property on them (and they’re only used in one union), you should prefer the global API config within your generators.yml
:
use_pydantic_field_aliases
Use Pydantic field aliases for property names that differ from wire format.
use_provided_defaults
Leverage defaults specified in the API specification.
use_typeddict_requests
Generate TypedDicts instead of Pydantic Models for request objects.
version
By default, the generator generates pydantic models that are v1 and v2 compatible. However you can override them to:
v1
: strictly use Pydantic v1v2
: strictly use Pydantic v2both
: maintain compatibility with both versionsv1_on_v2
: use Pydantic v1 compatibility layer on v2
wrapped_aliases
Enable wrapped aliases for Pydantic models. Only supported in Pydantic V1, V1_ON_V2, or V2.
use_inheritance_for_extended_models
Generate Pydantic models that implement inheritance when a model utilizes the Fern extends
keyword.