Skip to main content

https://vercel.com/docs/storage/vercel-kv/rest-api

Project description

vercel-kv-sdk

vercel-kv-sdk is a simple toolkit for vercel kv db which warped from vercel REST API

Document

QuickStart

install

pip install vercel-kv-sdk

Connect to a project

connect to project

Pull your vercel kv environment variables

vercel env pull .env.development.local

run this code to make the latest environment variables available to your project locally

rename your environment variables file

mv .env.development.local .env

then you can use vercel_kv_sdk in your project

from vercel_kv import KV

kv = KV()
kv.set("count",1)
count = kv.get("count")
print(f"now count is {count}")
# now count is 1

Using Options

In the SET command of Redis, there are several available options to configure the behavior of the command. Here are some common options in the SET command and their descriptions:

Options Description
ex Set the expiration time of the key in seconds. The key will be automatically deleted after the specified number of seconds.
px Set the expiration time of the key in milliseconds. The key will be automatically deleted after the specified number of milliseconds.
exat Set the value of the key only if it does not exist. If the key already exists, the SET command does not take effect.
pxat Set the value of the key only if it already exists. If the key does not exist, the SET command does not take effect.
keepTtl Preserve the existing expiration time of the key. Only used when overriding an existing key.

These options can be combined. For example, you can set the expiration time of the key to 10 seconds and set the value only if the key does not exist using the EX and NX options: SET key value EX 10 NX.

It is important to note that using options can have a certain impact on the performance of Redis, as additional operations will increase the overhead of command execution. Therefore, options should be used cautiously based on the actual requirements.

Example

kv = KV()
kv.set('temp','hello',ex=5)
print(f"now temp is {kv.get('temp')},and wait for 5 seconds...") # now temp is hello
time.sleep(5)
print(f"now temp is {kv.get('temp')}") # now temp is None

TODO

  • more user-friendly options input
  • complete functions: hset,hget

This project was forked from the python-vercel-kv project and improved,Lowering the python version threshold

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

vercel_kv_sdk-0.1.2.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

vercel_kv_sdk-0.1.2-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file vercel_kv_sdk-0.1.2.tar.gz.

File metadata

  • Download URL: vercel_kv_sdk-0.1.2.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.1

File hashes

Hashes for vercel_kv_sdk-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c6c3613f4a0ac5c698416bdb2b1ab7b6f922f849bd9227dc67e8d371df65f833
MD5 916e26ef2d9f2e9fb8b24c741a60ca14
BLAKE2b-256 f1b46dbd185d234e2f08558bbfc0f05ac632ae8597b9360054ee8ec72e0db33d

See more details on using hashes here.

File details

Details for the file vercel_kv_sdk-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for vercel_kv_sdk-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 86f91d5e292356d005f1a7cfa0f4208ac5ed82d5baf88b9a8b0980092e4afb71
MD5 04eb433460eb63b6f35fc3886cc6ac08
BLAKE2b-256 d30cfe1b45ddc8095c13bdda7f51669595e81a981c50349f691bf1dff28bc365

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page