A Python wrapper for the Cloudflare KV Cache API
Project description
CFKV
A simple wrapper to communicate with Cloudflare KV Store . It can be used as a cache and features will be implemented to be used in frameworks such as FastAPI
- Set and Get
- Fastapi Middleware
- Flask integration
- Options to include string instead of dict entry
Simple Usage
import datetime
from cfkv import KVStore
store = KVStore(namespace_id="YOUR_NAMESPACE_ID", account_id="ACCOUNT_ID", api_key="API_KEY")
# Usage Example
key = "sample_key"
get = store.get(key)
if get is None:
data = {"test": True, "date": str(datetime.datetime.now())}
store.set(key)
data['stored'] = False
get = data
else:
data['stored'] = True
print(get)
Setup
You will need to know your namespace id which is generated when you create a KV namespace and Account ID. To generate the KV api key follow the instructions below
- Navigate to Cloudflare API Tokens
- Create API Token
- Scroll down to create custom token
- Create a token with Workers KV Storage and select Edit
You can use environment variables to store these the following are monitored
KV_NAMESPACE_ID="YOUR_NAMESPACE_ID"
CF_ACCOUNT_ID="YOUR_ACCOUNT_ID"
CF_API_KEY="YOUR_API_KEY"
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
cfkv-1.1.1.tar.gz
(3.2 kB
view details)
File details
Details for the file cfkv-1.1.1.tar.gz
.
File metadata
- Download URL: cfkv-1.1.1.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c3651ba1b19d183a17717b431c97e2985b05867f6c42d36247dc65773d1e0c7 |
|
MD5 | 493d39da6c54d054a23c2645957e27ed |
|
BLAKE2b-256 | bcc4e81ca5554c6b6d1d96b6dde6148c522be8e75fb91c400fa7fc693edd0aad |