Upgrade to the Python v2 SDK with the Speakeasy CLI
To upgrade your Python SDK to Python v2 using the Speakeasy CLI, follow these four steps:
Update the gen.yaml
file
-
Add
templateVersion: v2
to the Python section of yourgen.yaml
file. -
If you have an
additionalDependencies
section underpython
, it needs modification. If you haven’t changed it previously, you can delete it and it will be recreated in the correct format. Otherwise, modify it from this:additionalDependencies:dependencies: {}extraDependencies:dev: {}To this:
additionalDependencies:dev: {}main: {}- Move any dependencies listed under the
dependencies
key tomain
. - Move any dependencies under
extraDependencies.dev
todev
. - Move any additional keys under
extraDependencies
to the top-leveladditionalDependencies
next to the other keys.
- Move any dependencies listed under the
Update the author
key
-
Change the old
author
key, underpython
, to the newauthors
key, which is an array of authors.python:authors:- Speakeasy# other configurations...
Generate the Python v2 SDK
- Run the
speakeasy run
command to generate the Python SDK.
Adjust the imports for Python v2
One of the main changes in Python v2 is how imported packages are handled. In version 1, sdkClassName
specified the top-level module. In version 2, packageName
is now used for imports, and matches the expected naming conventions for packages installed from PyPI. Some code imports may need to be adjusted for this change.
For example, given the sdkClassName
of speakeasy
and the packageName
of speakeasy-sdk
, the code was previously generated in the src/speakeasy
directory and imported as follows:
from speakeasy import Speakeasy
In version 2, the code is generated in the src/speakeasy_sdk
directory and imported as follows:
from speakeasy_sdk import Speakeasy
-
If you have custom hooks, move the custom hook files and the hook registration logic in
registration.py
from the oldsdkClassName
-based code-generation directory to the newpackageName
-based code-generation directory and update the imports accordingly:# Old importfrom speakeasy.hooks import CustomHook# New importfrom speakeasy_sdk.hooks import CustomHook -
If you do not have custom hooks, delete the old
src/speakeasy
folder:rm -rf src/speakeasy
Feel free to reach out if you encounter any issues or need further assistance!