Skip to main content
The Infrahub Python SDK is distributed as the infrahub-sdk package and can be installed using pip or uv.

Requirements

  • Python 3.12 or 3.13
  • Access to an Infrahub instance (API endpoint)

Installation Methods

Using pip

Install the SDK using pip:
pip install infrahub-sdk
uv is a fast Python package installer. Install with uv:
uv pip install infrahub-sdk
Or add to your project:
uv add infrahub-sdk

From Source

To install from the source repository:
git clone https://github.com/opsmill/infrahub.git
cd infrahub/python_sdk
uv pip install -e .

Verify Installation

Verify the SDK is installed correctly:
import infrahub_sdk
print(infrahub_sdk.__version__)
Or use the infrahubctl command-line tool:
infrahubctl --version

Dependencies

The SDK includes the following key dependencies:
  • httpx - Async HTTP client for API requests
  • pydantic - Data validation and settings management
  • rich - Beautiful terminal output
  • typer - CLI framework
  • pyarrow - Data serialization
All dependencies are installed automatically.

Development Installation

For SDK development, install with development dependencies:
cd infrahub
uv sync --all-groups
This installs:
  • Testing tools (pytest, pytest-asyncio)
  • Linting tools (ruff, mypy)
  • Type stubs

Environment Setup

Configuration File

Create an infrahub.toml configuration file:
[sdk]
address = "http://localhost:8000"
api_token = "your-api-token"

Environment Variables

Alternatively, use environment variables:
export INFRAHUB_ADDRESS="http://localhost:8000"
export INFRAHUB_API_TOKEN="your-api-token"

Docker

Use the SDK in a Docker container:
FROM python:3.12-slim

RUN pip install infrahub-sdk

COPY your_script.py /app/
WORKDIR /app

CMD ["python", "your_script.py"]

Upgrading

Upgrade to the latest version:
pip install --upgrade infrahub-sdk
Or with uv:
uv pip install --upgrade infrahub-sdk

Compatibility

The SDK version should match your Infrahub server version:
SDK VersionInfrahub VersionPython Version
1.7.x1.7.x3.12, 3.13
1.6.x1.6.x3.12

Troubleshooting

Import Errors

If you encounter import errors:
ModuleNotFoundError: No module named 'infrahub_sdk'
Ensure the SDK is installed in the correct Python environment:
python -m pip list | grep infrahub

Version Mismatch

If you see API compatibility errors, verify versions match:
from infrahub_sdk import InfrahubClient

client = InfrahubClient()
info = await client.info()
print(f"Server version: {info.version}")

Next Steps

Quick Start

Start using the SDK with a quick example

Build docs developers (and LLMs) love