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:To this:additionalDependencies:dependencies: {}extraDependencies:dev: {}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
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. Enterprise customers may encounter an error with hooks.
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. For example, if sdkClassName
was speakeasy
but packageName
was speakeasy-sdk
, the code was generated to src/speakeasy
, and imported like this:
from speakeasy import Speakeasy
In Python v2, packageName
is used for imports, matching the expected naming conventions for packages installed from PyPI. For the same values, the code will be generated to src/speakeasy_sdk
, and imported like this:
from speakeasy_sdk import Speakeasy
- If you have custom hooks, move them from
src/speakeasy
tosrc/speakeasy_sdk
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!