Python configuration options
This section details the available configuration options for the Python SDK. All configuration is managed in the gen.yaml file under the python section.
Identity and metadata
python:
version: 1.2.3
templateVersion: v2
packageName: "openapi"
moduleName: "openapi"
authors: ["Author Name"]
description: "Python Client SDK Generated by Speakeasy."
homepage: "https://example.com"
documentationUrl: "https://example.com/docs"
license: "Apache-2.0"Different package and module names
Configure a different name for the PyPI package and the module to import from:
python:
packageName: "my-package" # Install with: pip install my-package
moduleName: "my_module" # Import with: from my_module import SDKThis can be useful when the package name follows PyPI conventions (using hyphens) but the module name follows Python conventions (using underscores).
Build and tooling
python:
packageManager: "uv"
additionalDependencies:
main:
requests: "^2.25.1"
dev:
pytest: "^6.2.1"
compileCommands:
- ["uv", "lock"]
- ["uv", "sync", "--dev"]
- ["uv", "run", "python", "-m", "compileall", "-q", "."]
pytestFilterWarnings:
- error
- "ignore::DeprecationWarning"
pytestTimeout: 300Default compilation pipeline
When compileCommands is not set, the default pipeline runs based on the package manager (uv or poetry) and includes bytecode compilation (compileall), linting (pylint -j=0), and type checking (mypy and pyright in parallel). To reduce pylint parallelism and avoid OOM errors in CI, use compileCommands with -j=1.
API surface shape
python:
maxMethodParams: 999
flattenRequests: true
flatteningOrder: "parameters-first"
methodArguments: "infer-optional-args"
flattenGlobalSecurity: true
envVarPrefix: "SPEAKEASY"
responseFormat: "flat"
multipartArrayFormat: "standard"
imports:
option: "openapi"
paths:
callbacks: "models/callbacks"
errors: "models/errors"
operations: "models/operations"
shared: "models/shared"
webhooks: "models/webhooks"Import paths
Async and SSE
python:
asyncMode: split
useAsyncHooks: false
sseFlatResponse: falseThe asyncMode setting provides two patterns for handling async operations:
Method-based (both, default): Every operation has two methods — a synchronous version and an asynchronous version with an _async suffix.
sdk = MyAPI(api_key="...")
# Synchronous operations
result = sdk.list_users()
# Asynchronous operations
result = await sdk.list_users_async()Constructor-based (split): Separate constructors for synchronous and asynchronous clients. All method names are identical between sync and async versions.
# Synchronous client
sync_sdk = MyAPI(api_key="...")
result = sync_sdk.list_users()
# Asynchronous client
async_sdk = AsyncMyAPI(api_key="...")
result = await async_sdk.list_users()The constructor-based pattern eliminates method name duplication and provides clearer IDE suggestions.
Breaking change
Switching to asyncMode: split is a breaking change. Existing SDK consumers will need to update their code to use the new constructor pattern.
Errors
python:
clientServerStatusCodesAsErrors: true
defaultErrorName: ""
baseErrorName: "APIError"Enums and unions
python:
enumFormat: "union"
forwardCompatibleEnumsByDefault: true
forwardCompatibleUnionsByDefault: "tagged-only"
inferUnionDiscriminators: true
preApplyUnionDiscriminators: trueModels and miscellaneous
python:
inputModelSuffix: "input"
outputModelSuffix: "output"
constFieldCasing: "normal"
allowedRedefinedBuiltins:
- id
- object
- input
- dir
enableCustomCodeRegions: falseFixes
Fixes to apply to the generated SDK. Generally true for new SDKs but may be false for backward compatibility with existing SDKs.
python:
fixes:
responseRequiredSep2024: true
asyncPaginationSep2025: true
conflictResistantModelImportsFeb2026: trueLast updated on