Skip to main content
Infrahub provides a comprehensive command-line interface for managing your infrastructure data platform. The CLI offers commands for database management, server control, development workflows, and system maintenance.

CLI Tools

Infrahub includes two primary CLI tools:

infrahubctl

The main CLI tool for interacting with Infrahub. It provides commands for:
  • Database management and migrations
  • Server control and debugging
  • Interactive shell access
  • System upgrades
  • Development utilities
See infrahubctl Commands for detailed documentation.

infrahub (Python Package)

The infrahub Python package CLI is primarily used for server operations and is accessed via:
python -m infrahub.cli
In most cases, you’ll use infrahubctl for day-to-day operations.

Installation

The Infrahub CLI is installed automatically when you install Infrahub:
uv sync --all-groups
This makes the infrahubctl command available in your environment.

Configuration

Most CLI commands accept a configuration file path:
infrahubctl db migrate infrahub.toml
You can also use the INFRAHUB_CONFIG environment variable:
export INFRAHUB_CONFIG=/path/to/config.toml
infrahubctl db migrate
If no configuration file is specified, the CLI defaults to infrahub.toml in the current directory.

Command Structure

Infrahub CLI commands follow a hierarchical structure:
infrahubctl <command> [subcommand] [options] [arguments]
Examples:
infrahubctl server start --debug
infrahubctl db migrate --check
infrahubctl db patch plan <query-path>

Common Options

Most commands support these common options:
OptionDescriptionDefault
--helpShow help message and exit-
--debugEnable debug loggingFalse
config_filePath to configuration fileinfrahub.toml

Command Categories

Database Commands

Manage the graph database, run migrations, and perform maintenance:
  • infrahubctl db migrate - Apply database migrations
  • infrahubctl db constraint - Manage database constraints
  • infrahubctl db index - Manage database indexes
  • infrahubctl db check - Run database health checks
See Database Commands for complete reference.

Server Commands

Control the Infrahub API server:
  • infrahubctl server start - Start the API server in debug mode
See Server Commands for complete reference.

Development Commands

Utilities for development and testing:
  • infrahubctl dev db-init - Initialize a fresh database
  • infrahubctl dev export-graphql-schema - Export GraphQL schema
  • infrahubctl dev export-json-schema - Export OpenAPI schema
See infrahubctl Commands for complete reference.

Getting Help

Every command and subcommand supports the --help flag:
infrahubctl --help
infrahubctl db --help
infrahubctl db migrate --help

Exit Codes

The CLI uses standard exit codes:
  • 0 - Success
  • 1 - Error or failure
You can check the exit code in your shell:
infrahubctl db migrate
echo $?  # 0 on success, 1 on failure

Logging

The CLI outputs logs to stderr with varying levels of detail:
  • Default: INFO level messages
  • Debug mode (--debug): Detailed DEBUG level messages with timestamps
Example debug output:
infrahubctl server start --debug
2024-03-02 10:15:23 - infrahub.database - DEBUG - Connecting to database
2024-03-02 10:15:24 - infrahub.server - INFO - Starting server on 127.0.0.1:8000

Next Steps

Build docs developers (and LLMs) love