wrangler kv: Manage Workers KV from CI
wrangler kv manages Workers KV namespaces and the key/value pairs inside them from the command line.
KV is the simple edge key/value store for Workers. The CLI seeds data and provisions namespaces, both common steps in a deploy pipeline.
What it does
wrangler kv namespace create makes a namespace and prints its id for wrangler.toml. wrangler kv key put writes a value, kv key get reads one, kv key list enumerates keys, and kv bulk put loads many from a JSON array. You target a namespace by --binding (from wrangler.toml) or --namespace-id.
Common usage
wrangler kv namespace create CACHE
# write and read a key by binding name
wrangler kv key put --binding=CACHE "build:sha" "$GITHUB_SHA"
wrangler kv key get --binding=CACHE "build:sha"
# bulk load from a JSON array of {key,value}
wrangler kv bulk put --binding=CACHE data.jsonOptions
| Command / flag | What it does |
|---|---|
| namespace create <name> | Create a KV namespace, print its id |
| key put <k> <v> | Write a value |
| key get <k> | Read a value |
| key list | List keys in the namespace |
| bulk put <file> | Upload many key/value pairs from JSON |
| --binding <b> / --namespace-id <id> | Select the namespace |
In CI
Use --binding to reference the namespace by its wrangler.toml name so the same script works across environments; add --env to pick the environment-specific id. The same CLOUDFLARE_API_TOKEN and account id env vars apply as with deploy.
Common errors in CI
"Authentication error [code: 10000]" means a missing or under-scoped token (KV needs the Workers KV Storage permission). "Binding name not found" means the --binding has no matching kv_namespaces entry in wrangler.toml. In older wrangler the subcommand was kv:namespace / kv:key with a colon; the space form is current.