AI-powered CLI for executing GCP commands using natural language
Project description
GCP CLI
An AI-powered command-line interface for executing Google Cloud Platform commands using natural language.
Features
🤖 AI-Powered Command Generation - Use Vertex AI Gemini to generate GCP Python scripts from natural language queries
🛡️ Safe Execution - Preview generated code before execution with user confirmation
🔑 Flexible Authentication - Support for service account JSON files and Application Default Credentials
💻 Rich CLI Experience - Beautiful terminal output with syntax highlighting and interactive mode
📦 Modular Architecture - Easy to extend and customize for different GCP services
Installation
Prerequisites
- Python 3.8 or higher
- Google Cloud Platform account with Vertex AI enabled
- GCP credentials (Application Default Credentials recommended)
Quick Install (Recommended)
Install directly from GitHub:
pip install git+https://github.com/Cgraj07/gcp-cli.git
Install from Source
For development or if you want to modify the code:
# Clone the repository
git clone https://github.com/Cgraj07/gcp-cli.git
cd gcp-cli
# Install the package
pip install -e .
Quick Start
1. Set up credentials
Recommended: Use Application Default Credentials (ADC)
# Authenticate once - credentials stored securely
gcloud auth application-default login
That's it! The library will automatically use these credentials.
Alternative: Service Account Key (Not recommended for local development)
Only use this for CI/CD or production environments:
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/credentials.json"
2. Run your first command
# Execute a simple query
gcp-cli execute "list all compute instances in us-central1"
# Start interactive mode
gcp-cli interactive
# Run a Python script
gcp-cli run my_script.py
Usage
Execute Mode
Execute a natural language GCP command:
gcp-cli execute "list all cloud storage buckets"
gcp-cli execute "create a compute instance named test-vm in us-central1-a"
gcp-cli execute "list all IAM service accounts"
Options:
--no-preview: Skip code preview and execute immediately--dry-run: Generate code without executing--context: Add additional context for code generation
Interactive Mode
Start an interactive session for multiple commands:
gcp-cli interactive
In interactive mode, you can:
- Execute multiple commands in sequence
- View command history with
historycommand - Exit with
exitorquit
Run Script
Execute an existing Python script:
gcp-cli run my_gcp_script.py
Configuration
Create a configuration file:
gcp-cli init-config --output myconfig.yaml
Example config file (myconfig.yaml):
project_id: my-project
location: us-central1
model: gemini-2.0-flash-exp
max_output_tokens: 8192
temperature: 1.0
top_p: 0.95
preview_before_execute: true
log_level: INFO
Note: Authentication uses Application Default Credentials (ADC).
Rungcloud auth application-default loginbefore using the library.
Use a config file:
gcp-cli --config myconfig.yaml execute "list all instances"
View Information
Display current configuration:
gcp-cli info
View command history:
gcp-cli history
Python API
You can also use GCP CLI as a Python library:
from gcp_cli import GCPCommandExecutor, ConfigManager, CredentialManager
# Initialize
config = ConfigManager()
config.set('project_id', 'my-project')
config.set('location', 'us-central1')
credentials = CredentialManager(credentials_path='/path/to/creds.json')
executor = GCPCommandExecutor(config=config, credentials=credentials)
# Execute a query
result = executor.execute_natural_query(
query="list all compute instances",
preview=True,
dry_run=False
)
print(result['output'])
Command Examples
Here are some example queries you can try:
Compute Engine
- "list all compute instances"
- "create a compute instance named my-vm in us-central1-a with machine type n1-standard-1"
- "stop the instance named my-vm"
Cloud Storage
- "list all storage buckets"
- "create a storage bucket named my-bucket in us-central1"
- "upload file data.txt to bucket my-bucket"
Cloud SQL
- "list all cloud sql instances"
- "create a postgres cloud sql instance named my-db"
IAM
- "list all service accounts"
- "create a service account named my-sa"
- "list IAM roles for project"
Configuration Options
| Option | Description | Default |
|---|---|---|
project_id |
GCP project ID | None (auto-detected from credentials) |
location |
Default GCP location | us-central1 |
model |
Vertex AI model to use | gemini-2.0-flash-exp |
max_output_tokens |
Max tokens for code generation | 8192 |
temperature |
Generation temperature | 1.0 |
top_p |
Generation top_p | 0.95 |
preview_before_execute |
Show preview before execution | true |
log_level |
Logging level | INFO |
Environment Variables
You can override configuration with environment variables:
GOOGLE_APPLICATION_CREDENTIALS: Path to credentials JSONGCP_CLI_PROJECT_ID: Project IDGCP_CLI_LOCATION: GCP locationGCP_CLI_MODEL: Model name
Safety Features
- Code Preview: Review generated code before execution
- User Confirmation: Explicit confirmation required (unless
--no-preview) - Dry Run Mode: Test code generation without execution
- Command History: Track all executed commands
- Error Handling: Comprehensive error messages and logging
- Timeout Protection: 5-minute execution timeout
Project Structure
Cloud_AI/
├── gcp_cli/
│ ├── __init__.py # Package initialization
│ ├── cli.py # CLI interface
│ ├── executor.py # Command execution
│ ├── ai_generator.py # AI code generation
│ ├── credentials.py # Credential management
│ ├── config.py # Configuration handling
│ └── utils.py # Utility functions
├── examples/
│ └── basic_usage.py # Usage examples
├── setup.py # Package setup
├── requirements.txt # Dependencies
└── README.md # This file
Development
Running Tests
# Install development dependencies
pip install pytest pytest-cov
# Run tests
pytest tests/
Contributing
Contributions are welcome! Please ensure:
- Code follows PEP 8 style guidelines
- All tests pass
- New features include tests and documentation
Troubleshooting
"Failed to validate GCP credentials"
Authenticate with gcloud:
gcloud auth application-default login
"Project ID not found"
Provide project ID via:
- Config file:
project_id: my-project - Command line:
--project my-project - Environment:
export GCP_CLI_PROJECT_ID=my-project
"Model not found"
Ensure Vertex AI is enabled in your project:
gcloud services enable aiplatform.googleapis.com
License
MIT License - see LICENSE file for details
Support
For issues and questions:
- Open an issue on GitHub
- Check the documentation
- Review existing issues for similar problems
Acknowledgments
Built with:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gcp_cli_ai-0.2.0.tar.gz.
File metadata
- Download URL: gcp_cli_ai-0.2.0.tar.gz
- Upload date:
- Size: 30.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b3ba9de0956716f951004dffd6ebabfa7ed0ca8b440f86a89a95c37a6ecd2e0
|
|
| MD5 |
7326fe9081589677fb53a46bba84b79d
|
|
| BLAKE2b-256 |
8f60a29e653cf6e220a8275f510ab57bed8665f20dcc0b830a955c679ac7d510
|
File details
Details for the file gcp_cli_ai-0.2.0-py3-none-any.whl.
File metadata
- Download URL: gcp_cli_ai-0.2.0-py3-none-any.whl
- Upload date:
- Size: 16.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2669f587a8fea8bfc6561684f34ed84b637e40073339d7623042bca538a58c6f
|
|
| MD5 |
eaa35f56054243c03cf0468af7cb6a19
|
|
| BLAKE2b-256 |
566e6c5749fade5a6fa9482fcd197c0c5b22b56dee6fecf0efabe92f5a57810b
|