Upgrade to the Python v2 SDK with the Speakeasy CLI
To upgrade the Python SDK to Python v2 using the Speakeasy CLI, follow these four steps:
Update the gen.yaml file
-
Add
templateVersion: v2to the Python section of yourgen.yamlfile. -
If you have an
additionalDependenciessection 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:To this:
- Move any dependencies listed under the
dependencieskey tomain. - Move any dependencies under
extraDependencies.devtodev. - Move any additional keys under
extraDependenciesto the top-leveladditionalDependenciesnext to the other keys.
- Move any dependencies listed under the
Update the author key
-
Change the old
authorkey, underpython, to the newauthorskey, which is an array of authors.
Generate the Python v2 SDK
- Run the
speakeasy runcommand 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 generation previously occurred in the src/speakeasy directory with imports as follows:
In version 2, the code is generated in the src/speakeasy_sdk directory and imported as follows:
-
If you have custom hooks, move the custom hook files and the hook registration logic in
registration.pyfrom the oldsdkClassName-based code-generation directory to the newpackageName-based code-generation directory and update the imports accordingly: -
If you do not have custom hooks, delete the old
src/speakeasyfolder:
Feel free to reach out if you encounter any issues or need further assistance!
Last updated on