Skip to main content
kx — kubectl, indexed.

kubectl, indexed

PyPI version Python License CI

kx is a kubectl wrapper that adds index-based resource selection. Run kx get <resource> once, then reference any result by number instead of typing full resource names.

kx demo

Install

pip install kx-cli

Usage

List resources

kx get <resource> [--match|-m <substring>] [kubectl flags...]

Fetches resources and assigns index numbers. Any extra flags (e.g. -n <namespace>, -A) are passed through to kubectl. Use --match/-m to filter results by name (substring, case-insensitive).

$ kx get pods
Pods · default · 3 items
  X    NAME                      READY    STATUS     RESTARTS    AGE
  1    api-7d9f4b8c6-xkp2q       1/1      Running    0            2d
  2    worker-6c8b5f7d9-mnt4r    1/1      Running    3            5h
  3    postgres-0                1/1      Running    0           12d

All subsequent commands reference resources by their X index from the last kx get.

Global flags: --no-color disables styled output, --version prints the installed version, and --help on any command shows usage, examples, and aliases.

Commands

Command Description
kx get <resource> [--match/-m text] [kubectl flags...] List resources and assign index numbers for use with other commands.
kx describe <indexes>... [kubectl flags...] Show full kubectl describe output for one or more indexed resources.
kx events <indexes>... Show Kubernetes events for one or more indexed resources.
kx logs <index> [kubectl flags...] Stream logs for an indexed resource; aggregates across pods for Deployments, StatefulSets, DaemonSets, and Services.
kx labels <indexes>... [--selector/-s] Show labels for one or more indexed resources; --selector formats output as a label selector.
kx yaml <indexes>... [--show text] Print the raw YAML manifest for one or more indexed resources; --show filters to specific top-level fields.
kx delete <indexes>... [--yes/-y] Delete one or more indexed resources (prompts for confirmation unless --yes).
kx edit <index> [kubectl flags...] Open an indexed resource in your editor via kubectl edit.
kx exec <index> [<cmd>...] [kubectl flags...] Open an interactive shell in an indexed pod (bash, falling back to sh).
kx tree <index> [--index/-i] Show the ownership graph for an indexed resource; --index assigns indexes to tree nodes.
kx rollout <action> <index> Run a rollout action (status, restart, pause, resume, history, undo) on a Deployment, StatefulSet, or DaemonSet.
kx scale <index> <replicas> Scale an indexed Deployment, StatefulSet, or ReplicaSet to a given replica count.
kx port-forward <index> <port> [kubectl flags...] Forward a local port to an indexed resource (Pod, Deployment, ReplicaSet, StatefulSet, DaemonSet, Service).
kx diagnostic <index> Run read-only health diagnostics on an indexed Deployment, StatefulSet, DaemonSet, or Pod; alias: kx diag.
kx namespace <index> Switch to an indexed namespace; alias: kx ns (run kx get namespaces first).
kx theme [<name>] List available color themes or persist a choice by name or index.
kx state [<position>] [--all/-a] Show current state, jump to a history position, or list all entries with --all.
kx drop <position> Remove a history entry by position (shown in kx state --all).
kx back Navigate to the previous kx get result.
kx forward Navigate to the next kx get result.

Example workflow

# list deployments, pick index 2
kx get deployments
kx describe 2

# check events on that deployment
kx events 2

# drill into a pod
kx get pods
kx logs 1
kx exec 1            # opens bash/sh
kx exec 1 -- env     # run a specific command

# forward local port 8080 to port 80 on a service
kx get services
kx port-forward 2 8080:80

# navigate history after multiple gets
kx get pods
kx get deployments
kx logs 1            # logs from pod index 1
kx state --all       # review full history

# clean up
kx delete 3

State

kx maintains a history of up to 10 kx get results in ~/.kx/state.json. A cursor tracks your current position; index-based commands always resolve against the entry at the cursor.

$ kx get pods          # saves a new entry, cursor advances
$ kx get deployments   # saves another entry, cursor advances
$ kx logs 1            # resolves index 1 from the pods result
$ kx state --all       # lists all history entries and the current position

Use kx state <position> to jump directly to any history entry, and kx drop <position> to remove one.

Configuration

kx reads ~/.kx/config.toml; environment variables override file settings.

Key Env var Default Description
max_history KX_MAX_HISTORY 10 Number of kx get results kept in history.
shells KX_SHELLS (comma-separated) ["bash", "sh"] Shell candidates for kx exec.
no_color KX_NO_COLOR false Disable styled output (same as --no-color).
theme KX_THEME "github-dark" Color theme for all output.

Styled output is emitted only when stdout is a terminal — piped or redirected output is plain text, so kx get pods | grep worker stays clean. The NO_COLOR convention is honored as well.

Themes

kx theme        # list available themes (indexed) with a preview of each
kx theme nord   # persist a theme to ~/.kx/config.toml
kx theme 3      # same, selecting by index from the kx theme listing

Prefab themes: github-dark (default), dracula, nord, gruvbox, solarized-dark, catppuccin-mocha, tokyo-night, rose-pine, mono, light (for light terminal backgrounds), and plain (no styling at all).

Development

python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"

Run the CLI directly:

python -m kx.main --help

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kx_cli-0.0.6.tar.gz (56.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kx_cli-0.0.6-py3-none-any.whl (40.6 kB view details)

Uploaded Python 3

File details

Details for the file kx_cli-0.0.6.tar.gz.

File metadata

  • Download URL: kx_cli-0.0.6.tar.gz
  • Upload date:
  • Size: 56.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for kx_cli-0.0.6.tar.gz
Algorithm Hash digest
SHA256 4f1b75fbe0da9e4a585b767eaba0708ab0cafb4e6675e41e43a1d07240a41016
MD5 30e6d500345790ca3e8f4505aa4916a1
BLAKE2b-256 5003e98f52a69d0109d2642917b87a9d9b6bd5d0314843b9774ddb4b9e75f6bb

See more details on using hashes here.

File details

Details for the file kx_cli-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: kx_cli-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 40.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for kx_cli-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 a622dfbb6944dc7da05e8db551e995dfc9577eba24add062f2304064ffbefeac
MD5 e1da73d40cdd1aa8e64015e198883974
BLAKE2b-256 28d91cf6af5711b6ba3445468ebc5d89ad84b503de6e24ca957a46164fc764b3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page