InfraGPT
A CLI tool that converts natural language requests into Google Cloud (gcloud) commands.
Installation
Using pip
Using pip to install packages system-wide is not recommended. Instead, install InfraGPT using pipx in the next section.
Using pipx
# Install pipx if you don't have it
pip install --user pipx
pipx ensurepath
# Install infragpt
pipx install infragpt
From Source
-
Clone the repository:
git clone https://github.com/priyanshujain/infragpt.git cd infragpt -
Install in development mode:
pip install -e .
Credentials Management
InfraGPT requires API keys to work. There are three ways to provide credentials, in order of priority:
1. Command Line Parameters
# Using OpenAI GPT-4o
infragpt --model gpt4o --api-key "your-openai-api-key" "your prompt here"
# Using Anthropic Claude
infragpt --model claude --api-key "your-anthropic-api-key" "your prompt here"
2. Configuration File
InfraGPT stores credentials in ~/.config/infragpt/config.yaml and uses them automatically on subsequent runs. This file is created:
- When you provide credentials interactively
- Automatically on first run if environment variables are available
- When you use command line parameters
3. Environment Variables
Set one or more of these environment variables:
# For OpenAI GPT-4o
export OPENAI_API_KEY="your-openai-api-key"
# For Anthropic Claude
export ANTHROPIC_API_KEY="your-anthropic-api-key"
# Optionally specify the model
export INFRAGPT_MODEL="gpt4o" # or "claude"
Model Selection Rules:
- If both API keys are set, InfraGPT uses OpenAI by default unless specified otherwise
- If only one API key is set, the corresponding model is used automatically
- If a model is explicitly selected (via command line or INFRAGPT_MODEL), the corresponding API key must be available
When environment variables are available, InfraGPT will automatically save the detected model and API key to the configuration file for future use.
If no credentials are found from any of these sources, if an empty API key is detected, or if an invalid API key is provided, InfraGPT will prompt you to select a model and enter your API key interactively at startup, before accepting any commands.
API Key Validation:
- The application validates API keys by making a small test request to the service provider
- When entering credentials interactively, API keys are validated immediately
- Invalid keys from environment variables or the config file are detected at startup
- The system will continue prompting until valid credentials are provided
- All validated credentials are automatically saved to the config file
Usage
InfraGPT has two main subcommands:
generate: Convert natural language to Google Cloud commands (default command)history: View or export your command history
Command Generation
Generate gcloud commands from natural language:
infragpt generate "create a new VM instance called test-vm in us-central1 with 2 CPUs"
You can also use the tool without specifying the command:
infragpt "create a new VM instance called test-vm in us-central1 with 2 CPUs"
Or use the special -- syntax to handle arguments that might conflict with CLI options:
infragpt -- "create a new VM instance called test-vm in us-central1 with 2 CPUs"
Specify the model to use:
infragpt --model claude "list all my compute instances in europe-west1"
Interactive Mode
Launch InfraGPT in interactive mode (no initial prompt):
infragpt
Use keyboard shortcuts in interactive mode:
Ctrl+Dto exit the applicationCtrl+Cto clear the current input and start a new prompt
Command History
View your recent command history:
infragpt history
Limit the number of entries:
infragpt history --limit 20
Filter by interaction type:
infragpt history --type command_execution
Export your history to a file:
infragpt history --export history.jsonl
Example Commands
- "Create a new GKE cluster with 3 nodes in us-central1"
- "List all storage buckets"
- "Create a Cloud SQL MySQL instance named 'mydb' in us-west1"
- "Set up a load balancer for my instance group 'web-servers'"
Options
Generate Command Options
--model,-m: Choose the LLM model (gpt4o or claude)--api-key,-k: Provide an API key for the selected model--verbose,-v: Enable verbose output
History Command Options
--limit,-l: Number of history entries to display (default: 10)--type,-t: Filter by interaction type (command_generation, command_action, command_execution)--export,-e: Export history to specified file path
Contributing
For information on how to contribute to InfraGPT, including development setup, release process, and CI/CD configuration, please see the CONTRIBUTING.md file.
Metadata
Release files for infragpt 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| infragpt-0.1.3.tar.gz | 28.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| infragpt-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 56.2 kB
Release files / infragpt-0.1.3.tar.gz
| Download URL | infragpt-0.1.3.tar.gz |
|---|---|
| Size | 28.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
82fbc5e8d978a073ac43fdcc78803a8631930218d0694fdc68cb44f35b257ead
|
|
BLAKE2b-256 checksum How to use checksums |
d6270a54238d18a986448405a2057f11536d71050bd241804e59fc4233ceb25b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.11
|
Release files / infragpt-0.1.3-py3-none-any.whl
| Download URL | infragpt-0.1.3-py3-none-any.whl |
|---|---|
| Size | 27.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c66ee9bf88cd215ec53a58a4ac72fa3ca4625ce28d5d2095d854f477ed88af1f
|
|
BLAKE2b-256 checksum How to use checksums |
24b3dcb4c8a95d7255438e9f07abaebbfb84ae01f744bae0fc22f671886168c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.11
|