Skip to main content
The gRPC API is in legacy maintenance mode and won’t receive new features. For new projects, use the REST v2beta API.

Basic Installation

The Python gRPC SDK is published to PyPI and can be installed just like any other Python package via pip. All you need to do to install it is run:

Developer Installation

For access to bleeding-edge features, you can build the package from source code. The recommended installation for most purposes is the basic install described above. Before getting started with the API, we need to set up a local development environment. Following this article will walk you through how to set up your local development environment, download our repository (which includes everything you need to get started), and verify your environment setup.

0. (Optional) Create and activate a Python virtual environment…

Using the venv module which ships with your Python install, create a virtual environment named “venv” thusly:
We’re invoking python3 here to access the ‘system’ Python executable. To activate the environment:
When the environment has been successfully activated, you should see the environment name as a prefix in your terminal prompt, e.g.
With the environment activated, invoking python will access the Python executable for the activated environment, rather than the system Python. Installing Python packages — either from source as described below or via pip — will only impact the environment Python executable. To deactivate the virtual environment, simply run the command deactivate.

1. Clone the stability-sdk repository from GitHub…

The stability-sdk repository (as of 0.3.0) has dependencies on git submodules. To fetch these submodules while cloning, use the --recurse-submodules argument:
If you cloned without this argument, you can pull the submodule dependencies by running the following commands after navigating into the repository:
if there is a specific branch you want to clone, you can use the --branch argument:
Alternatively, you can use the switch command after cloning to pull and checkout into any branch hosted at the origin remote (following these instructions, your origin remote will be set to https://github.com/stability-ai/stability-sdk.git). After navigating into the repository:

2. Navigate into the stability-sdk repository directory…

3. Install the Python SDK…

To use pip to install from the local codebase rather than pulling a package from PyPI, we simply pass the current location (i.e. .) as an argument:
If you plan to make changes to the local code, you may find it useful to install in “editable” mode, which will respect your code changes as soon as you make them. Otherwise, you will need to reinstall after each change. To install in editable mode, we just add the -e argument:

4. Optionally, set the STABILITY_HOST and STABILITY_KEY environment variables…

We’ll set these inside the example scripts as well, but this sets them in the environment so that you don’t need to pass these values as explicit arguments. Note that export is Linux / MacOS syntax. If you are using Windows, you will need to use the set command instead.

5. Invoke the API to test your setup…

Following successful installation you should see connection and generation logs output to your terminal and the image generated by your request saved to your current directory.