xx
.md

cf_kv_create

cf_kv_create asynchronously creates a Workers KV namespace when no namespace with the same title exists. Existing namespaces are reused. The returned resource can be passed directly through any deps argument.

The resource has name and id fields. Reading id waits for provisioning and returns the namespace ID as a string.

Arguments

ArgumentRequiredDescription
nameYesNamespace name passed to Wrangler.
previewNoCreate the remote preview namespace. Its actual title, exposed as resource.name, is <name>_preview. Defaults to False.
depsNoDependencies activated before running Wrangler. Use these to provide Wrangler, credentials, or an account ID.

Example

This example expects package.json to list "wrangler": "4.123.0" in devDependencies.

load("@cloudflare@1", "cf_kv_create")
load("@[email protected]", "npm_install")
load("@os@1", "env_prepend", "env_set")

wrangler = npm_install() + env_prepend("PATH", "node_modules/.bin")
account = env_set("CLOUDFLARE_ACCOUNT_ID", "0123456789abcdef0123456789abcdef")
cache = cf_kv_create("app-cache", deps=[wrangler, account])

print(cache.id)