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
| Argument | Required | Description |
|---|---|---|
name | Yes | Namespace name passed to Wrangler. |
preview | No | Create the remote preview namespace. Its actual title, exposed as resource.name, is <name>_preview. Defaults to False. |
deps | No | Dependencies 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)