Access Cloudflare KV in Python

Hi All,

When trying to access our KV namespace from Python ( it works fine for me in JS) I get:

TypeError: KWD.py_get is not a function

I seem to be able to find examples of people using it in exactly this way, what am I missing?

Here is my TOML:

kv_namespaces = [
  {binding = "KWD", id = "{id}", preview_id="{p_id}"}
]

And my function in index.py:

def getSomeData(w):
    data = KWD.get(w)
    return data

I feel like is this a SMH moment, but any help much appreciated!

Thanks.

get is aliased by transcrypt, use js_get:

so your handler might look something like

def handleRequest(request):
    return KV.js_get('foo').then(
        lambda v: __new__(Response('Python Worker hello world! ' + v, {
        'headers' : { 'content-type' : 'text/plain' }
})))

I’ll add a note to the README

1 Like

Thanks! I just gave up and wrote it in JS.

That would definitely be good to add to the READE.