KV commands
kv:namespace
Manage KV namespaces.
The kv:... commands allow you to manage application data in the Cloudflare network to be accessed from Workers using KV.
 create
Creates a new KV namespace.
- NAMESPACE- string- The name of the new namespace.
 
- --env- string- Perform on a specific environment.
 
- --preview- boolean- Interact with a preview namespace (the preview_idvalue).
 
- Interact with a preview namespace (the 
create command to create a KV namespace called MY_KV
create command to create a preview KV namespace called MY_KV
 list
Lists all KV namespaces associated with the current account ID.
Pass the Wrangler command through the jq command
 delete
Deletes a given KV namespace.
- --binding- string- The binding name of the namespace, as stored in the wrangler.tomlfile, to delete.
 
- The binding name of the namespace, as stored in the 
- --namespace-id- string- The ID of the namespace to delete.
 
- --env- string- Perform on a specific environment.
 
- --preview- boolean- Interact with a preview namespace instead of production.
 
 Delete a KV namespace called MY_KV
 Delete a preview KV namespace called MY_KV
kv:key
Manage key-value pairs within a KV namespace.
 put
Writes a single key-value pair to a particular KV namespace.
- KEY- string- The key to write to.
 
- VALUE- string- The value to write.
 
- --path- 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 
- --binding- string- The binding name of the KV namespace, as stored in the wrangler.tomlfile, to delete.
 
- The binding name of the KV namespace, as stored in the 
- --namespace-id- string- The ID of the KV namespace to delete.
 
- --env- string- Perform on a specific environment.
 
- --preview- boolean- Interact with a preview namespace instead of production.
 
- --ttl- number- 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 
- --expiration- number- The timestamp, in UNIX seconds, indicating when the key-value pair should expire.
 
- --metadata- string- Any (escaped) JSON serialized arbitrary object to a maximum of 1024 bytes.
 
Put a key-value into the KV namespace with binding name of MY_KV
Put a key-value into the preview KV namespace with binding name of MY_KV
Put a key-value into a KV namespace, with a time-to-live value of 10000 seconds
Put a key-value into a KV namespace, where the value is read from the value.txt file
 get
Reads a single value by key from the given KV namespace.
- KEY- string- The key value to get.
 
- --binding- string- The binding name of the namespace, as stored in the wrangler.tomlfile, to delete.
 
- The binding name of the namespace, as stored in the 
- --namespace-id- string- The ID of the namespace to delete.
 
- --env- string- Perform on a specific environment.
 
- --preview- boolean- Interact with a preview namespace instead of production.
 
Gets the value of the "my-key" key from the KV namespace with binding name MY_KV
 list
Outputs a list of all keys in a given KV namespace.
- --binding- string- The binding name of the namespace, as stored in the wrangler.tomlfile, to delete.
 
- The binding name of the namespace, as stored in the 
- --namespace-id- string- The ID of the namespace to delete.
 
- --env- string- Perform on a specific environment.
 
- --preview- boolean- Interact with a preview namespace instead of production.
 
- --prefix- string- Only list keys that begin with the given prefix.
 
Pass the Wrangler command through the jq command
 delete
Removes a single key value pair from the given namespace.
- KEY- string- The key value to get.
 
- --binding- string- The binding name of the namespace, as stored in the wrangler.tomlfile, to delete.
 
- The binding name of the namespace, as stored in the 
- --namespace-id- string- The ID of the namespace to delete.
 
- --env- string- Perform on a specific environment.
 
- --preview- boolean- Interact with a preview namespace instead of production.
 
Deletes the key-value pair with key "my-key" from the KV namespace with binding name MY_KV
kv:bulk
Manage multiple key-value pairs within a KV namespace in batches.
put
Writes a JSON file containing an array of key-value pairs to the given namespace.
- FILENAME- string- The JSON file containing an array of key-value pairs to write to the namespace.
 
- --binding- string- The binding name of the namespace, as stored in the wrangler.tomlfile, to delete.
 
- The binding name of the namespace, as stored in the 
- --namespace-id- string- The ID of the namespace to delete.
 
- --env- string- Perform on a specific environment.
 
- --preview- boolean- Interact with a preview namespace instead of production.
 
This command takes a JSON file as an argument with a list of key-value pairs to upload. An example of JSON input:
KV namespace values can only store strings. In order to save complex a value, stringify it to JSON:
Here is the full schema for key-value entries uploaded via the bulk API:
- key- string- The key’s name. The name may be 512 bytes maximum. All printable, non-whitespace characters are valid.
 
- value- string- The UTF-8 encoded string to be stored, up to 25 MB in length.
 
- metadata- object- Any arbitrary object (must serialize to JSON) to a maximum of 1024 bytes.
 
- expiration- number- The time, measured in number of seconds since the UNIX epoch, at which the key should expire.
 
- expiration_ttl- number- 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 
- base64- boolean- 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 
Writing all the key-value pairs found in the allthethingsupload.json file
 delete
Deletes all keys read from a JSON file within a given namespace.
- FILENAME- string- The JSON file containing an array of keys to delete from the namespace.
 
- --binding- string- The binding name of the namespace, as stored in the wrangler.tomlfile, to delete.
 
- The binding name of the namespace, as stored in the 
- --namespace-id- string- The ID of the namespace to delete.
 
- --env- string- Perform on a specific environment.
 
- --preview- boolean- Interact with a preview namespace instead of production.
 
This command takes a JSON file as an argument containing an array of keys to delete. Here is an example of the JSON input:
Delete all the keys found in the allthethingsdelete.json file