Upgrading to Python v2 SDK With Speakeasy CLI
To upgrade your Python SDK to version 2 using the Speakeasy CLI, please follow these steps:
1. Update the gen.yaml
file
-
Add
templateVersion: v2
to the Python section of yourgen.yaml
file. -
If you have an
additionalDependencies
section under Python, it needs modification. If it hasn’t been changed 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.
2. Update the author
key
-
Change the old
author
key underpython
to a newauthors
key, which is an array of authors.python:authors:- Speakeasy# other configurations...
3. Generate the Python v2 SDK
- Run
speakeasy run
to generate the Python v2 SDK.
4. Adjust imports for Python v2
One of the main changes in Python v2 is how imported packages are handled. In version 1, the sdkClassName
specified the top-level module. In version 2, packageName
is used for imports, matching the expected naming conventions for packages installed from PyPI. Some code imports may need to be adjusted for this change.
For example, given sdkClassName
of speakeasy
and packageName
of speakeasy-sdk
, previously the code is generated in the src/speakeasy
directory and imported with:
from speakeasy import Speakeasy
In version 2, the code is generated in the src/speakeasy_sdk
directory and imported with:
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 imports accordingly. For example:# 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!