> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stability.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Python gRPC SDK

> Install and configure the legacy Stability AI Python gRPC SDK (stability-sdk) and make your first generation request.

> [!WARNING]
>
> The gRPC API is in legacy maintenance mode and won't receive new features. For new projects, use the [REST v2beta API](https://docs.stability.ai/api-reference/generate/stable-image-ultra.md).

## Basic Installation

The Python gRPC SDK is published to [PyPI](https://pypi.org/project/stability-sdk/) and can be installed just like any other Python package via `pip`. All you need to do to install it is run:

```bash theme={null}
pip install stability-sdk
```

## 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:

```bash theme={null}
python3 -m venv venv
```

We're invoking `python3` here to access the 'system' Python executable.

To activate the environment:

```bash theme={null}
source venv/bin/activate
```

When the environment has been successfully activated, you should see the environment name as a prefix in your terminal prompt, e.g.

```bash theme={null}
# prompt before activating
/path/to/current/directory >

# prompt after activating
(venv) /path/to/current/directory >
```

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:

```bash theme={null}
git clone --recurse-submodules https://github.com/Stability-AI/stability-sdk
```

If you cloned without this argument, you can pull the submodule dependencies by running the following commands after navigating into the repository:

```bash theme={null}
git submodule init
git submodule update
```

if there is a specific branch you want to clone, you can use the `--branch` argument:

```bash theme={null}
git clone --branch branchName --recurse-submodules https://github.com/Stability-AI/stability-sdk
```

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](https://github.com/stability-ai/stability-sdk.git)). After navigating into the repository:

```bash theme={null}
git fetch
git switch branchName
```

### 2. Navigate into the `stability-sdk` repository directory...

```bash theme={null}
cd stability-sdk
```

### 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:

```bash theme={null}
pip install .
```

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:

```bash theme={null}
pip install -e .
```

### 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.

```bash theme={null}
# Sign up for an account at the following link to get an API Key.
# https://platform.stability.ai/

# Click on the following link once you have created an account to be taken to your API Key.
# https://platform.stability.ai/dashboard/api-keys

# Paste your API Key below.

export STABILITY_HOST=grpc.stability.ai:443
export STABILITY_KEY=yourkeyhere
```

### 5. Invoke the API to test your setup...

```bash theme={null}
python -m stability_sdk generate "A stunning house."
```

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.
