cfkv


Namecfkv JSON
Version 1.1.1 PyPI version JSON
download
home_page
SummaryA Python wrapper for the Cloudflare KV Cache API
upload_time2023-10-24 13:42:48
maintainer
docs_urlNone
authorPaul Gardiner
requires_python
licenseMIT
keywords cloudflare kv cache api cloudflare workers
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # CFKV

[![Deploy > PYPI > Test ](https://github.com/mooncitizen/python-cfkv/actions/workflows/testpypi.yaml/badge.svg)](https://github.com/mooncitizen/python-cfkv/actions/workflows/testpypi.yaml)

[![Release](https://github.com/mooncitizen/python-cfkv/actions/workflows/pypi.yaml/badge.svg)](https://github.com/mooncitizen/python-cfkv/actions/workflows/pypi.yaml)

A simple wrapper to communicate with [Cloudflare KV Store ](https://developers.cloudflare.com/kv/). It can be used as a cache and features will be implemented to be used in frameworks such as ```FastAPI```

- [x] Set and Get
- [ ] Fastapi Middleware
- [ ] Flask integration
- [x] Options to include string instead of dict entry

### Simple Usage

```python
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

1. Navigate to [Cloudflare API Tokens](https://dash.cloudflare.com/profile/api-tokens)
2. Create API Token
3. Scroll down to create custom token
4. Create a token with **Workers KV Storage** and select **Edit**

![Example Token](github/image.png)

You can use environment variables to store these the following are monitored
```python
KV_NAMESPACE_ID="YOUR_NAMESPACE_ID"
CF_ACCOUNT_ID="YOUR_ACCOUNT_ID"
CF_API_KEY="YOUR_API_KEY"
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "cfkv",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "cloudflare,kv,cache,api,cloudflare workers",
    "author": "Paul Gardiner",
    "author_email": "franticstone@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/bc/c4/e81ca5554c6b6d1d96b6dde6148c522be8e75fb91c400fa7fc693edd0aad/cfkv-1.1.1.tar.gz",
    "platform": null,
    "description": "# CFKV\n\n[![Deploy > PYPI > Test ](https://github.com/mooncitizen/python-cfkv/actions/workflows/testpypi.yaml/badge.svg)](https://github.com/mooncitizen/python-cfkv/actions/workflows/testpypi.yaml)\n\n[![Release](https://github.com/mooncitizen/python-cfkv/actions/workflows/pypi.yaml/badge.svg)](https://github.com/mooncitizen/python-cfkv/actions/workflows/pypi.yaml)\n\nA simple wrapper to communicate with [Cloudflare KV Store ](https://developers.cloudflare.com/kv/). It can be used as a cache and features will be implemented to be used in frameworks such as ```FastAPI```\n\n- [x] Set and Get\n- [ ] Fastapi Middleware\n- [ ] Flask integration\n- [x] Options to include string instead of dict entry\n\n### Simple Usage\n\n```python\nimport datetime\nfrom cfkv import KVStore\n\nstore = KVStore(namespace_id=\"YOUR_NAMESPACE_ID\", account_id=\"ACCOUNT_ID\", api_key=\"API_KEY\")\n\n# Usage Example\nkey = \"sample_key\"\nget = store.get(key)\n\nif get is None:\n    data = {\"test\": True, \"date\": str(datetime.datetime.now())}\n    store.set(key)\n    data['stored'] = False\n    get = data\nelse:\n    data['stored'] = True\n\nprint(get)\n```\n\n### Setup\n\nYou 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\n\n1. Navigate to [Cloudflare API Tokens](https://dash.cloudflare.com/profile/api-tokens)\n2. Create API Token\n3. Scroll down to create custom token\n4. Create a token with **Workers KV Storage** and select **Edit**\n\n![Example Token](github/image.png)\n\nYou can use environment variables to store these the following are monitored\n```python\nKV_NAMESPACE_ID=\"YOUR_NAMESPACE_ID\"\nCF_ACCOUNT_ID=\"YOUR_ACCOUNT_ID\"\nCF_API_KEY=\"YOUR_API_KEY\"\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python wrapper for the Cloudflare KV Cache API",
    "version": "1.1.1",
    "project_urls": null,
    "split_keywords": [
        "cloudflare",
        "kv",
        "cache",
        "api",
        "cloudflare workers"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bcc4e81ca5554c6b6d1d96b6dde6148c522be8e75fb91c400fa7fc693edd0aad",
                "md5": "493d39da6c54d054a23c2645957e27ed",
                "sha256": "2c3651ba1b19d183a17717b431c97e2985b05867f6c42d36247dc65773d1e0c7"
            },
            "downloads": -1,
            "filename": "cfkv-1.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "493d39da6c54d054a23c2645957e27ed",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3179,
            "upload_time": "2023-10-24T13:42:48",
            "upload_time_iso_8601": "2023-10-24T13:42:48.051890Z",
            "url": "https://files.pythonhosted.org/packages/bc/c4/e81ca5554c6b6d1d96b6dde6148c522be8e75fb91c400fa7fc693edd0aad/cfkv-1.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-24 13:42:48",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "cfkv"
}
        
Elapsed time: 0.18751s