Skip to main content

Python Design

The Python SDKs are designed to be easy to use and easy to debug.

Fully Typed

Modern Python provides type-hints to developers, and that's something that Speakeasy-generated Python SDKs expose to users. Here's a bit of the code that we generate from Swagger's Petstore OpenAPI schema.

class Pet:
name: str = field(metadata={'dataclasses_json': {'letter_case': utils.field_name('name')}})
photo_urls: list[str] = field(metadata={'dataclasses_json': {'letter_case': utils.field_name('photoUrls')}})
category: Optional[shared.Category] = field(default=None, metadata={
'dataclasses_json': {'letter_case': utils.field_name('category')}})
id: Optional[int] = field(default=None, metadata={'dataclasses_json': {'letter_case': utils.field_name('id')}})
status: Optional[PetStatusEnum] = field(default=None,
metadata={'dataclasses_json': {'letter_case': utils.field_name('status')}})
tags: Optional[list[shared.Tag]] = field(default=None,
metadata={'dataclasses_json': {'letter_case': utils.field_name('tags')}})

Using dataclasses for all the models we generate allows us to append per field metadata to correctly serialize and deserialize models based on the definitions provided by the OpenAPI document, whether they're serialized as query-parameters, path-parameters, or request-bodies.

If you have any feedback or want to suggest improvements or ask for a new feature please get in contact in the #client-sdks channel in our public Slack.