Wrangler KV commands
Manage Workers KV namespaces.
Create a new namespace.
wrangler kv namespace create <NAMESPACE> [OPTIONS]NAMESPACEstring required- The name of the new namespace.
--envstring optional- Perform on a specific environment.
--previewboolean optional- Interact with a preview namespace (the
preview_idvalue).
- Interact with a preview namespace (the
The following global flags work on every command:
--helpboolean- Show help.
--configstring (not supported by Pages)- Path to your Wrangler configuration file.
--cwdstring- Run as if Wrangler was started in the specified directory instead of the current working directory.
The following is an example of using the create command to create a KV namespace called MY_KV.
npx wrangler kv namespace create "MY_KV"🌀 Creating namespace with title "worker-MY_KV"✨ Success!Add the following to your configuration file in your kv_namespaces array:kv_namespaces = [ { binding = "MY_KV", id = "e29b263ab50e42ce9b637fa8370175e8" }]The following is an example of using the create command to create a preview KV namespace called MY_KV.
npx wrangler kv namespace create "MY_KV" --preview🌀 Creating namespace with title "my-site-MY_KV_preview"✨ Success!Add the following to your configuration file in your kv_namespaces array:kv_namespaces = [ { binding = "MY_KV", preview_id = "15137f8edf6c09742227e99b08aaf273" }]List all KV namespaces associated with the current account ID.
wrangler kv namespace listThe following global flags work on every command:
--helpboolean- Show help.
--configstring (not supported by Pages)- Path to your Wrangler configuration file.
--cwdstring- Run as if Wrangler was started in the specified directory instead of the current working directory.
The following is an example that passes the Wrangler command through the jq command:
npx wrangler kv namespace list | jq "."[ { "id": "06779da6940b431db6e566b4846d64db", "title": "TEST_NAMESPACE" }, { "id": "32ac1b3c2ed34ed3b397268817dea9ea", "title": "STATIC_CONTENT" }]Delete a given namespace.
wrangler kv namespace delete {--binding=<BINDING>|--namespace-id=<NAMESPACE_ID>} [OPTIONS]--bindingstring- The binding name of the namespace, as stored in the Wrangler file, to delete.
--namespace-idstring- The ID of the namespace to delete.
--envstring optional- Perform on a specific environment.
--previewboolean optional- Interact with a preview namespace instead of production.
The following global flags work on every command:
--helpboolean- Show help.
--configstring (not supported by Pages)- Path to your Wrangler configuration file.
--cwdstring- Run as if Wrangler was started in the specified directory instead of the current working directory.
The following is an example of deleting a KV namespace called MY_KV.
npx wrangler kv namespace delete --binding=MY_KVAre you sure you want to delete namespace f7b02e7fc70443149ac906dd81ec1791? [y/n]yesDeleting namespace f7b02e7fc70443149ac906dd81ec1791Deleted namespace f7b02e7fc70443149ac906dd81ec1791The following is an example of deleting a preview KV namespace called MY_KV.
npx wrangler kv namespace delete --binding=MY_KV --previewAre you sure you want to delete namespace 15137f8edf6c09742227e99b08aaf273? [y/n]yesDeleting namespace 15137f8edf6c09742227e99b08aaf273Deleted namespace 15137f8edf6c09742227e99b08aaf273Manage key-value pairs within a Workers KV namespace.
Write a single key-value pair to a particular namespace.
wrangler kv key put <KEY> {<VALUE>|--path=<PATH>} {--binding=<BINDING>|--namespace-id=<NAMESPACE_ID>} [OPTIONS]KEYstring required- The key to write to.
VALUEstring optional- The value to write.
--pathoptional- When defined, the value is loaded from the file at
--pathrather than reading it from theVALUEargument. This is ideal for security-sensitive operations because it avoids saving keys and values into your terminal history.
- When defined, the value is loaded from the file at
--bindingstring- The binding name of the namespace, as stored in the Wrangler file, to write to.
--namespace-idstring- The ID of the namespace to write to.
--envstring optional- Perform on a specific environment.
--previewboolean optional- Interact with a preview namespace instead of production.
--ttlnumber optional- The lifetime (in number of seconds) that the key-value pair should exist before expiring. Must be at least
60seconds. This option takes precedence over theexpirationoption.
- The lifetime (in number of seconds) that the key-value pair should exist before expiring. Must be at least
--expirationnumber optional- The timestamp, in UNIX seconds, indicating when the key-value pair should expire.
--metadatastring optional- Any (escaped) JSON serialized arbitrary object to a maximum of 1024 bytes.
--localboolean optional- Interact with locally persisted data.
--persist-tostring optional- Specify directory for locally persisted data.
The following global flags work on every command:
--helpboolean- Show help.
--configstring (not supported by Pages)- Path to your Wrangler configuration file.
--cwdstring- Run as if Wrangler was started in the specified directory instead of the current working directory.
The following is an example that puts a key-value into the namespace with binding name of MY_KV.
npx wrangler kv key put --binding=MY_KV "my-key" "some-value"Writing the value "some-value" to key "my-key" on namespace f7b02e7fc70443149ac906dd81ec1791.The following is an example that puts a key-value into the preview namespace with binding name of MY_KV.
npx wrangler kv key put --binding=MY_KV --preview "my-key" "some-value"Writing the value "some-value" to key "my-key" on namespace 15137f8edf6c09742227e99b08aaf273.The following is an example that puts a key-value into a namespace, with a time-to-live value of 10000 seconds.
npx wrangler kv key put --binding=MY_KV "my-key" "some-value" --ttl=10000Writing the value "some-value" to key "my-key" on namespace f7b02e7fc70443149ac906dd81ec1791.The following is an example that puts a key-value into a namespace, where the value is read from the value.txt file.
npx wrangler kv key put --binding=MY_KV "my-key" --path=value.txtWriting the contents of value.txt to the key "my-key" on namespace f7b02e7fc70443149ac906dd81ec1791.Output a list of all keys in a given namespace.
wrangler kv key list {--binding=<BINDING>|--namespace-id=<NAMESPACE_ID>} [OPTIONS]--bindingstring- The binding name of the namespace, as stored in the Wrangler file, to list from.
--namespace-idstring- The ID of the namespace to list from.
--envstring optional- Perform on a specific environment.
--previewboolean optional- Interact with a preview namespace instead of production.
--prefixstring optional- Only list keys that begin with the given prefix.
--localboolean optional- Interact with locally persisted data.
--persist-tostring optional- Specify directory for locally persisted data.
The following global flags work on every command:
--helpboolean- Show help.
--configstring (not supported by Pages)- Path to your Wrangler configuration file.
--cwdstring- Run as if Wrangler was started in the specified directory instead of the current working directory.
Below is an example that passes the Wrangler command through the jq command:
npx wrangler kv key list --binding=MY_KV --prefix="public" | jq "."[ { "name": "public_key" }, { "name": "public_key_with_expiration", "expiration": "2019-09-10T23:18:58Z" }]Read a single value by key from the given namespace.
wrangler kv key get <KEY> {--binding=<BINDING>|--namespace-id=<NAMESPACE_ID>} [OPTIONS]KEYstring required- The key value to get.
--bindingstring- The binding name of the namespace, as stored in the Wrangler file, to get from.
--namespace-idstring- The ID of the namespace to get from.
--envstring optional- Perform on a specific environment.
--previewboolean optional- Interact with a preview namespace instead of production.
--textboolean optional- Decode the returned value as a UTF-8 string.
--localboolean optional- Interact with locally persisted data.
--persist-tostring optional- Specify directory for locally persisted data.
The following global flags work on every command:
--helpboolean- Show help.
--configstring (not supported by Pages)- Path to your Wrangler configuration file.
--cwdstring- Run as if Wrangler was started in the specified directory instead of the current working directory.
The following is an example that gets the value of the "my-key" key from the KV namespace with binding name MY_KV.
npx wrangler kv key get --binding=MY_KV "my-key"valueRemove a single key value pair from the given namespace.
wrangler kv key delete <KEY> {--binding=<BINDING>|--namespace-id=<NAMESPACE_ID>} [OPTIONS]KEYstring required- The key value to get.
--bindingstring- The binding name of the namespace, as stored in the Wrangler file, to delete from.
--namespace-idstring- The ID of the namespace to delete from.
--envstring optional- Perform on a specific environment.
--previewboolean optional- Interact with a preview namespace instead of production.
--localboolean optional- Interact with locally persisted data.
--persist-tostring optional- Specify directory for locally persisted data.
The following global flags work on every command:
--helpboolean- Show help.
--configstring (not supported by Pages)- Path to your Wrangler configuration file.
--cwdstring- Run as if Wrangler was started in the specified directory instead of the current working directory.
The following is an example that deletes the key-value pair with key "my-key" from the KV namespace with binding name MY_KV.
npx wrangler kv key delete --binding=MY_KV "my-key"Deleting the key "my-key" on namespace f7b02e7fc70443149ac906dd81ec1791.Manage multiple key-value pairs within a Workers KV namespace in batches.
Write a JSON file containing an array of key-value pairs to the given namespace.
wrangler kv bulk put <FILENAME> {--binding=<BINDING>|--namespace-id=<NAMESPACE_ID>} [OPTIONS]FILENAMEstring required- The JSON file containing an array of key-value pairs to write to the namespace.
--bindingstring- The binding name of the namespace, as stored in the Wrangler file, to write to.
--namespace-idstring- The ID of the namespace to write to.
--envstring optional- Perform on a specific environment.
--previewboolean optional- Interact with a preview namespace instead of production.
--localboolean optional- Interact with locally persisted data.
--persist-tostring optional- Specify directory for locally persisted data.
The following global flags work on every command:
--helpboolean- Show help.
--configstring (not supported by Pages)- Path to your Wrangler configuration file.
--cwdstring- Run as if Wrangler was started in the specified directory instead of the current working directory.
This command takes a JSON file as an argument with a list of key-value pairs to upload. An example of JSON input:
[ { "key": "test_key", "value": "test_value", "expiration_ttl": 3600 }]KV namespace values can only store strings. In order to save complex a value, stringify it to JSON:
[ { "key": "test_key", "value": "{\"name\": \"test_value\"}", "expiration_ttl": 3600 }]Refer to the full schema for key-value entries uploaded via the bulk API:
keystring required- The key’s name. The name may be 512 bytes maximum. All printable, non-whitespace characters are valid.
valuestring required- The UTF-8 encoded string to be stored, up to 25 MB in length.
metadataobject optional- Any arbitrary object (must serialize to JSON) to a maximum of 1,024 bytes.
expirationnumber optional- The time, measured in number of seconds since the UNIX epoch, at which the key should expire.
expiration_ttlnumber optional- The number of seconds the document should exist before expiring. Must be at least
60seconds.
- The number of seconds the document should exist before expiring. Must be at least
base64boolean optional- When true, the server will decode the value as base64 before storing it. This is useful for writing values that would otherwise be invalid JSON strings, such as images. Defaults to
false.
- When true, the server will decode the value as base64 before storing it. This is useful for writing values that would otherwise be invalid JSON strings, such as images. Defaults to
The following is an example of writing all the key-value pairs found in the allthethingsupload.json file.
npx wrangler kv bulk put --binding=MY_KV allthethingsupload.jsonSuccess!Delete all keys read from a JSON file within a given namespace.
wrangler kv bulk delete <FILENAME> {--binding=<BINDING>|--namespace-id=<NAMESPACE_ID>} [OPTIONS]FILENAMEstring required- The JSON file containing an array of keys to delete from the namespace.
--bindingstring- The binding name of the namespace, as stored in the Wrangler file, to delete from.
--namespace-idstring- The ID of the namespace to delete from.
--envstring optional- Perform on a specific environment.
--previewboolean optional- Interact with a preview namespace instead of production.
--localboolean optional- Interact with locally persisted data.
--persist-tostring optional- Specify directory for locally persisted data.
The following global flags work on every command:
--helpboolean- Show help.
--configstring (not supported by Pages)- Path to your Wrangler configuration file.
--cwdstring- Run as if Wrangler was started in the specified directory instead of the current working directory.
This command takes a JSON file as an argument containing the keys to delete.
The following is an example of the JSON input:
["test_key_1", "test_key_2"]The command also accepts keys in the format output from wrangler kv key list:
[{ "name": "test_key_1" }, { "name": "test_key_2" }]The following is an example of deleting all the keys found in the allthethingsdelete.json file.
npx wrangler kv bulk delete --binding=MY_KV allthethingsdelete.json? Are you sure you want to delete all keys in allthethingsdelete.json from kv-namespace with id "f7b02e7fc70443149ac906dd81ec1791"? › (Y/n)Success!Below are deprecations to Wrangler commands for Workers KV.
Since version 3.60.0, Wrangler supports the kv ... syntax. If you are using versions below 3.60.0, the command follows the kv:... syntax.
The kv:... syntax is deprecated in versions 3.60.0 and beyond and will be removed in a future major version.
For example, commands using the kv ... syntax look as such:
wrangler kv namespace listwrangler kv key get <KEY>wrangler kv bulk put <FILENAME>The same commands using the kv:... syntax look as such:
wrangler kv:namespace listwrangler kv:key get <KEY>wrangler kv:bulk put <FILENAME>Was this helpful?
- Resources
- API
- New to Cloudflare?
- Products
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark