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 your gen.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 to main.

  • Move any dependencies under extraDependencies.dev to dev.

  • Move any additional keys under extraDependencies to the top-level additionalDependencies next to the other keys.

2. Update the author key

  • Change the old author key under python to a new authors 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 old sdkClassName-based code generation directory to the new packageName-based code generation directory and update imports accordingly. For example:

    # Old import
    from speakeasy.hooks import CustomHook
    # New import
    from 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!