Skip to main content
Lesson 4 of 14 · Mistral API: Quick Start

Install the Mistral Python SDK

Lesson 4 of 14 Updated November 2, 2026 Developer
On this page
  1. Prerequisites
  2. Isolate your project before installing anything
  3. Install the official SDK
  4. Verify the installation with a real API call
  5. Make the environment reproducible
  6. Four common failures and how to diagnose them
  7. Key takeaways

Prerequisites

Updated November 2, 2026 — Mistral SDK 3. This lesson previously covered SDK version 2 and Python 3.9. The current version is 3.7.0 (released November 1, 2026); it requires Python 3.10 or higher, and the client is imported via from mistralai.client import Mistral as of version 2.0 (March 2026). Sources: mistralai on PyPI · v2.0.0 release notes · v3.0.0 release notes.

Installing the SDK requires three things: Python 3.10 or higher, which you can verify with python --version; an up-to-date pip, obtained via pip install --upgrade pip; and your Mistral API key already set as an environment variable, as covered in the previous lesson. If Python isn’t installed on your machine yet, grab the latest stable release from python.org or use your system’s package manager.

Isolate your project before installing anything

Always work inside a virtual environment. This habit saves you from a common headache: two projects on the same machine, one requiring a specific SDK version and the other a different one, where a single pip install silently breaks the first project by updating the second. A virtual environment gives each project its own isolated dependencies, separate from your system-wide packages.

# Create the virtual environment
python -m venv mistral-env

# Activate on Linux / macOS
source mistral-env/bin/activate

# Activate on Windows
mistral-env\Scripts\activate

Once activated, your terminal prompt will be prefixed with the environment name in parentheses: (mistral-env). This small marker guarantees that subsequent commands apply to the correct location—if it doesn’t appear, do not install anything.

Install the official SDK

Installing the Mistral SDK takes a single command:

pip install mistralai

This installs the latest SDK version: 3.7.0 as of November 1, 2026. Generation 3 began with version 3.0, released on September 28, 2026. To confirm everything is in place, run pip show mistralai to display the package name, version, and dependencies.

Sometimes a project requires a specific version, for instance, to keep an entire team aligned during a migration. You can specify constraints at two levels:

# Stay within generation 3
pip install "mistralai>=3,<4"

# Install an exact version
pip install "mistralai==3.7.0"

Along the way, pip pulls in a few dependencies that appear in the list. It helps to recognize them, particularly httpx2, the HTTP client handling network calls (the SDK uses this instead of httpx starting with version 3.0), and pydantic, which validates and serializes exchanged data. You won’t interact with these directly, but their presence explains why an installation that seems tiny still occupies a few megabytes.

Verify the installation with a real API call

Running pip show proves the package exists, not that your configuration works. The real test queries the API. Create a file named test_mistral.py:

import os
from mistralai.client import Mistral

api_key = os.environ.get("MISTRAL_API_KEY")

if not api_key:
    print("Error: MISTRAL_API_KEY environment variable is not set.")
else:
    client = Mistral(api_key=api_key)
    print("Mistral client initialized successfully!")

    # List available models
    models = client.models.list()
    print(f"Available models: {len(models.data)}")
    for model in models.data[:5]:
        print(f"  - {model.id}")

Then run it:

python test_mistral.py

This script checks two things at once. The check on api_key immediately distinguishes a missing environment variable from a genuine network issue—without it, you might spend ten minutes suspecting your firewall when the terminal was simply reopened without the variable. If the model list displays, the SDK is installed correctly and your key is accepted by the API.

Make the environment reproducible

On a team project, the installation must be reproducible. Freeze your dependencies:

pip freeze > requirements.txt

Your colleagues can then reconstruct the exact same environment with a single command:

pip install -r requirements.txt

Your deployment server will also read this file. Get into the habit of regenerating it every time you add a library; otherwise, the code will work on your machine and nowhere else.

Four common failures and how to diagnose them

The error ModuleNotFoundError: No module named mistralai almost always means the terminal isn’t using the correct virtual environment. Verify this with which python, which should point to your venv, and then with pip list | grep mistralai.

The error ImportError: cannot import name 'Mistral' from 'mistralai' indicates code written for SDK version 1. Since version 2.0, all imports go through mistralai.client: write from mistralai.client import Mistral. The lesson on SDK versions details other changes.

An SSL or network error often reveals a corporate proxy sitting between you and the outside world. Explicitly tell pip about it:

pip install mistralai --proxy http://proxy.entreprise.com:8080

Finally, if the installation rejects your Python version, remember that the SDK has required Python 3.10 minimum since version 2.0. Update Python, or install pyenv to run multiple versions side-by-side without touching the system interpreter.

Key takeaways

  • Install the SDK with pip install mistralai inside a virtual environment
  • The current version is 3.7.0 (November 1, 2026); import the client via from mistralai.client import Mistral
  • Verify the installation by listing available models
  • Freeze dependencies in requirements.txt for reproducibility
  • Python 3.10 or higher is required