# Values ## Read key-value pair `kv.namespaces.values.get(strkey_name, ValueGetParams**kwargs) -> BinaryResponseContent` **get** `/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/values/{key_name}` Returns the value associated with the given key in the given namespace. Use URL-encoding to use special characters (for example, `:`, `!`, `%`) in the key name. If the KV-pair is set to expire at some point, the expiration time as measured in seconds since the UNIX epoch will be returned in the `expiration` response header. ### Parameters - `account_id: str` Identifier. - `namespace_id: str` Namespace identifier tag. - `key_name: str` A key's name. The name may be at most 512 bytes. All printable, non-whitespace characters are valid. Use percent-encoding to define key names as part of a URL. ### Returns - `BinaryResponseContent` ### Example ```python import os from cloudflare import Cloudflare client = Cloudflare( api_token=os.environ.get("CLOUDFLARE_API_TOKEN"), # This is the default and can be omitted ) value = client.kv.namespaces.values.get( key_name="My-Key", account_id="023e105f4ecef8ad9ca31a8372d0c353", namespace_id="0f2ac74b498b48028cb68387c421e279", ) print(value) content = value.read() print(content) ``` ## Write key-value pair with optional metadata `kv.namespaces.values.update(strkey_name, ValueUpdateParams**kwargs) -> ValueUpdateResponse` **put** `/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/values/{key_name}` Write a value identified by a key. Use URL-encoding to use special characters (for example, `:`, `!`, `%`) in the key name. Body should be the value to be stored. If JSON metadata to be associated with the key/value pair is needed, use `multipart/form-data` content type for your PUT request (see dropdown below in `REQUEST BODY SCHEMA`). Existing values, expirations, and metadata will be overwritten. If neither `expiration` nor `expiration_ttl` is specified, the key-value pair will never expire. If both are set, `expiration_ttl` is used and `expiration` is ignored. ### Parameters - `account_id: str` Identifier. - `namespace_id: str` Namespace identifier tag. - `key_name: str` A key's name. The name may be at most 512 bytes. All printable, non-whitespace characters are valid. Use percent-encoding to define key names as part of a URL. - `value: Union[str, FileTypes]` A byte sequence to be stored, up to 25 MiB in length. - `str` - `FileTypes` - `expiration: Optional[float]` Expires the key at a certain time, measured in number of seconds since the UNIX epoch. - `expiration_ttl: Optional[float]` Expires the key after a number of seconds. Must be at least 60. - `metadata: Optional[object]` Associates arbitrary JSON data with a key/value pair. ### Returns - `class ValueUpdateResponse: …` ### Example ```python import os from cloudflare import Cloudflare client = Cloudflare( api_token=os.environ.get("CLOUDFLARE_API_TOKEN"), # This is the default and can be omitted ) value = client.kv.namespaces.values.update( key_name="My-Key", account_id="023e105f4ecef8ad9ca31a8372d0c353", namespace_id="0f2ac74b498b48028cb68387c421e279", value="Some Value", ) print(value) ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": {} } ``` ## Delete key-value pair `kv.namespaces.values.delete(strkey_name, ValueDeleteParams**kwargs) -> ValueDeleteResponse` **delete** `/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/values/{key_name}` Remove a KV pair from the namespace. Use URL-encoding to use special characters (for example, `:`, `!`, `%`) in the key name. ### Parameters - `account_id: str` Identifier. - `namespace_id: str` Namespace identifier tag. - `key_name: str` A key's name. The name may be at most 512 bytes. All printable, non-whitespace characters are valid. Use percent-encoding to define key names as part of a URL. ### Returns - `class ValueDeleteResponse: …` ### Example ```python import os from cloudflare import Cloudflare client = Cloudflare( api_token=os.environ.get("CLOUDFLARE_API_TOKEN"), # This is the default and can be omitted ) value = client.kv.namespaces.values.delete( key_name="My-Key", account_id="023e105f4ecef8ad9ca31a8372d0c353", namespace_id="0f2ac74b498b48028cb68387c421e279", ) print(value) ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": {} } ``` ## Domain Types ### Value Update Response - `class ValueUpdateResponse: …` ### Value Delete Response - `class ValueDeleteResponse: …`