Skip to main content
Manage Workers KV Namespaces and key-value pairs from the command line.

Commands

Namespace Management

Create a new KV namespace.
wrangler kv namespace create <namespace>
namespace
string
required
The name of the new namespace
Options:
--preview
boolean
Interact with a preview namespace
--env
string
Environment to use for operations and .env files
--update-config
boolean
Automatically update your wrangler configuration file with the new namespace binding (defaults to interactive prompt)
--binding-name
string
The name of the binding to use for the namespace in your wrangler configuration file
Example:
wrangler kv namespace create MY_KV
Output a list of all KV namespaces associated with your account.
wrangler kv namespace list
Example:
wrangler kv namespace list
Returns JSON array of namespace objects with id and title properties.
Delete a KV namespace.
wrangler kv namespace delete [namespace]
namespace
string
The name of the namespace to delete
Options:
--binding
string
The binding name to the namespace to delete from
--namespace-id
string
The id of the namespace to delete
--preview
boolean
Interact with a preview namespace
--skip-confirmation
boolean
Skip confirmation (alias: -y)
Example:
wrangler kv namespace delete MY_KV
wrangler kv namespace delete --namespace-id abc123
You must specify one of: namespace name, --binding, or --namespace-id.
Rename a KV namespace.
wrangler kv namespace rename [old-name] --new-name <new-name>
old-name
string
The current name of the namespace to rename
Options:
--namespace-id
string
The id of the namespace to rename
--new-name
string
required
The new name for the namespace (max 512 characters)
Example:
wrangler kv namespace rename OLD_NAME --new-name NEW_NAME
wrangler kv namespace rename --namespace-id abc123 --new-name NEW_NAME
You must specify either old-name or --namespace-id.

Key Operations

Write a single key/value pair to a namespace.
wrangler kv key put <key> [value]
key
string
required
The key to write to
value
string
The value to write
Options:
--binding
string
The binding name to the namespace to write to
--namespace-id
string
The id of the namespace to write to
--preview
boolean
Interact with a preview namespace
--path
string
Read value from the file at a given path
--ttl
number
Time for which the entries should be visible (in seconds)
--expiration
number
Time since the UNIX epoch after which the entry expires
--metadata
string
Arbitrary JSON that is associated with a key
--local
boolean
Interact with local storage
--remote
boolean
Interact with remote storage
--persist-to
string
Directory for local persistence
Example:
wrangler kv key put mykey "myvalue" --binding=MY_KV
wrangler kv key put mykey --path=./file.txt --namespace-id=abc123
wrangler kv key put mykey "value" --ttl=3600 --metadata='{"tag":"production"}' --binding=MY_KV
You must provide either --value or --path, and either --binding or --namespace-id.
Read a single value by key from a namespace.
wrangler kv key get <key>
key
string
required
The key value to get
Options:
--binding
string
The binding name to the namespace to get from
--namespace-id
string
The id of the namespace to get from
--preview
boolean
default:"false"
Interact with a preview namespace
--text
boolean
default:"false"
Decode the returned value as a utf8 string
--local
boolean
Interact with local storage
--remote
boolean
Interact with remote storage
--persist-to
string
Directory for local persistence
Example:
wrangler kv key get mykey --binding=MY_KV
wrangler kv key get mykey --namespace-id=abc123 --text
You must provide either --binding or --namespace-id.
Output a list of all keys in a namespace.
wrangler kv key list
Options:
--binding
string
The binding name to the namespace to list
--namespace-id
string
The id of the namespace to list
--preview
boolean
default:"false"
Interact with a preview namespace
--prefix
string
A prefix to filter listed keys
--local
boolean
Interact with local storage
--remote
boolean
Interact with remote storage
--persist-to
string
Directory for local persistence
Example:
wrangler kv key list --binding=MY_KV
wrangler kv key list --namespace-id=abc123 --prefix="user:"
Returns JSON array of key objects.
Remove a single key value pair from a namespace.
wrangler kv key delete <key>
key
string
required
The key value to delete
Options:
--binding
string
The binding name to the namespace to delete from
--namespace-id
string
The id of the namespace to delete from
--preview
boolean
Interact with a preview namespace
--local
boolean
Interact with local storage
--remote
boolean
Interact with remote storage
--persist-to
string
Directory for local persistence
Example:
wrangler kv key delete mykey --binding=MY_KV
wrangler kv key delete mykey --namespace-id=abc123

Bulk Operations

Upload multiple key-value pairs to a namespace from a JSON file.
wrangler kv bulk put <filename>
filename
string
required
The file containing the key/value pairs to write
Options:
--binding
string
The binding name to the namespace to write to
--namespace-id
string
The id of the namespace to write to
--preview
boolean
Interact with a preview namespace
--ttl
number
Time for which the entries should be visible
--expiration
number
Time since the UNIX epoch after which the entry expires
--metadata
string
Arbitrary JSON that is associated with a key
--local
boolean
Interact with local storage
--remote
boolean
Interact with remote storage
--persist-to
string
Directory for local persistence
File format:
[
  {
    "key": "key1",
    "value": "value1",
    "expiration_ttl": 3600,
    "metadata": {"tag": "production"},
    "base64": false
  },
  {
    "key": "key2",
    "value": "value2"
  }
]
Example:
wrangler kv bulk put data.json --binding=MY_KV
Gets multiple key-value pairs from a namespace.
wrangler kv bulk get <filename>
filename
string
required
The file containing the keys to get
Options:
--binding
string
The binding name to the namespace to get from
--namespace-id
string
The id of the namespace to get from
--preview
boolean
default:"false"
Interact with a preview namespace
--local
boolean
Interact with local storage
--remote
boolean
Interact with remote storage
--persist-to
string
Directory for local persistence
File format:
["key1", "key2", "key3"]
Or with object format:
[
  {"name": "key1"},
  {"name": "key2"}
]
Example:
wrangler kv bulk get keys.json --binding=MY_KV
Returns JSON object mapping keys to their values.
Delete multiple key-value pairs from a namespace.
wrangler kv bulk delete <filename>
filename
string
required
The file containing the keys to delete
Options:
--binding
string
The binding name to the namespace to delete from
--namespace-id
string
The id of the namespace to delete from
--preview
boolean
Interact with a preview namespace
--force
boolean
Do not ask for confirmation before deleting (alias: -f)
--local
boolean
Interact with local storage
--remote
boolean
Interact with remote storage
--persist-to
string
Directory for local persistence
File format:
["key1", "key2", "key3"]
Or with object format:
[
  {"name": "key1"},
  {"name": "key2"}
]
Example:
wrangler kv bulk delete keys.json --binding=MY_KV
wrangler kv bulk delete keys.json --namespace-id=abc123 --force

Build docs developers (and LLMs) love