redis-sdk


Nameredis-sdk JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/khulnasoft-lab/redispy
SummaryServerless Redis SDK from Khulnasoft
upload_time2023-12-09 02:25:46
maintainerKhulnasoft
docs_urlNone
authorKhulnasoft
requires_python>=3.8,<4.0
licenseMIT
keywords khulnasoft redis serverless redis
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Khulnasoft Redis Python SDK

redis-sdk is a connectionless, HTTP-based Redis client for Python, designed to be used in serverless and serverful environments such as:
- AWS Lambda
- Vercel Serverless
- Google Cloud Functions
- and other environments where HTTP is preferred over TCP.

Inspired by other Redis clients like [@khulnasoft/redis](https://github.com/khulnasoft-lab/redis-sdk) and [redis-py](https://github.com/redis/redis-py),
the goal of this SDK is to provide a simple way to use Redis over the [Khulnasoft REST API](https://docs.khulnasoft.com/redis/features/restapi).

The SDK is currently compatible with Python 3.8 and above.

<!-- toc -->

- [Khulnasoft Redis Python SDK](#redis-sdk-python-sdk)
- [Quick Start](#quick-start)
  - [Install](#install)
    - [PyPI](#pypi)
  - [Usage](#usage)
    - [BITFIELD and BITFIELD\_RO](#bitfield-and-bitfield_ro)
    - [Custom commands](#custom-commands)
- [Encoding](#encoding)
- [Retry mechanism](#retry-mechanism)
- [Contributing](#contributing)
  - [Preparing the environment](#preparing-the-environment)
  - [Running tests](#running-tests)

<!-- tocstop -->

# Quick Start

## Install

### PyPI
```bash
pip install redis-sdk
```

## Usage
To be able to use redis-sdk, you need to create a database on [Khulnasoft](https://console.khulnasoft.com/)
and grab `REDIS_SDK_REST_URL` and `REDIS_SDK_REST_TOKEN` from the console.

```python
# for sync client
from redis_sdk import Redis

redis = Redis(url="REDIS_SDK_REST_URL", token="REDIS_SDK_REST_TOKEN")

# for async client
from redis_sdk.asyncio import Redis

redis = Redis(url="REDIS_SDK_REST_URL", token="REDIS_SDK_REST_TOKEN")
```

Or, if you want to automatically load the credentials from the environment:

```python
# for sync use
from redis_sdk import Redis
redis = Redis.from_env()

# for async use
from redis_sdk.asyncio import Redis
redis = Redis.from_env()
```

If you are in a serverless environment that allows it, it's recommended to initialise the client outside the request handler
to be reused while your function is still hot.

Running commands might look like this:

```python
from redis_sdk import Redis

redis = Redis.from_env()

def main():
  redis.set("a", "b")
  print(redis.get("a"))

# or for async context:

from redis_sdk.asyncio import Redis

redis = Redis.from_env()

async def main():  
  await redis.set("a", "b")
  print(await redis.get("a"))
```

### BITFIELD and BITFIELD_RO
One particular case is represented by these two chained commands, which are available as functions that return an instance of 
the `BITFIELD` and, respectively, `BITFIELD_RO` classes. Use the `execute` function to run the commands.

```python
redis.bitfield("test_key") \
  .incrby(encoding="i8", offset=100, increment=100) \
  .overflow("SAT") \
  .incrby(encoding="i8", offset=100, increment=100) \
  .execute()

redis.bitfield_ro("test_key_2") \
  .get(encoding="u8", offset=0) \
  .get(encoding="u8", offset="#1") \
  .execute()
```

### Custom commands
If you want to run a command that hasn't been implemented, you can use the `execute` function of your client instance
and pass the command as a `list`.

```python
redis.execute(command=["XLEN", "test_stream"])
```

# Encoding
Although Redis can store invalid JSON data, there might be problems with the deserialization.
To avoid this, the Khulnasoft REST proxy is capable of encoding the data as base64 on the server and then sending it to the client to be
decoded. 

For very large data, this can add a few milliseconds in latency. So, if you're sure that your data is valid JSON, you can set
`rest_encoding` to `None`.

# Retry mechanism
redis-sdk has a fallback mechanism in case of network or API issues. By default, if a request fails it'll retry once, 3 seconds 
after the error. If you want to customize that, set `rest_retries` and `rest_retry_interval` (in seconds).

# Contributing

## Preparing the environment
This project uses [Poetry](https://python-poetry.org) for packaging and dependency management. Make sure you are able to create the poetry shell with relevant dependencies.

You will also need a database on [Khulnasoft](https://console.khulnasoft.com/).

## Running tests
To run all the tests, make sure the poetry virtual environment activated with all 
the necessary dependencies. Set the `REDIS_SDK_REST_URL` and `REDIS_SDK_REST_TOKEN` environment variables and run:

```bash
poetry run pytest
```
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/khulnasoft-lab/redispy",
    "name": "redis-sdk",
    "maintainer": "Khulnasoft",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "support@khulnasoft.com",
    "keywords": "Khulnasoft Redis,Serverless Redis",
    "author": "Khulnasoft",
    "author_email": "support@khulnasoft.com",
    "download_url": "https://files.pythonhosted.org/packages/be/37/a5e7161cb4f0211139d7f7b3fecdd3f6b13c621ec91668c0e4b55608776c/redis_sdk-1.0.0.tar.gz",
    "platform": null,
    "description": "# Khulnasoft Redis Python SDK\n\nredis-sdk is a connectionless, HTTP-based Redis client for Python, designed to be used in serverless and serverful environments such as:\n- AWS Lambda\n- Vercel Serverless\n- Google Cloud Functions\n- and other environments where HTTP is preferred over TCP.\n\nInspired by other Redis clients like [@khulnasoft/redis](https://github.com/khulnasoft-lab/redis-sdk) and [redis-py](https://github.com/redis/redis-py),\nthe goal of this SDK is to provide a simple way to use Redis over the [Khulnasoft REST API](https://docs.khulnasoft.com/redis/features/restapi).\n\nThe SDK is currently compatible with Python 3.8 and above.\n\n<!-- toc -->\n\n- [Khulnasoft Redis Python SDK](#redis-sdk-python-sdk)\n- [Quick Start](#quick-start)\n  - [Install](#install)\n    - [PyPI](#pypi)\n  - [Usage](#usage)\n    - [BITFIELD and BITFIELD\\_RO](#bitfield-and-bitfield_ro)\n    - [Custom commands](#custom-commands)\n- [Encoding](#encoding)\n- [Retry mechanism](#retry-mechanism)\n- [Contributing](#contributing)\n  - [Preparing the environment](#preparing-the-environment)\n  - [Running tests](#running-tests)\n\n<!-- tocstop -->\n\n# Quick Start\n\n## Install\n\n### PyPI\n```bash\npip install redis-sdk\n```\n\n## Usage\nTo be able to use redis-sdk, you need to create a database on [Khulnasoft](https://console.khulnasoft.com/)\nand grab `REDIS_SDK_REST_URL` and `REDIS_SDK_REST_TOKEN` from the console.\n\n```python\n# for sync client\nfrom redis_sdk import Redis\n\nredis = Redis(url=\"REDIS_SDK_REST_URL\", token=\"REDIS_SDK_REST_TOKEN\")\n\n# for async client\nfrom redis_sdk.asyncio import Redis\n\nredis = Redis(url=\"REDIS_SDK_REST_URL\", token=\"REDIS_SDK_REST_TOKEN\")\n```\n\nOr, if you want to automatically load the credentials from the environment:\n\n```python\n# for sync use\nfrom redis_sdk import Redis\nredis = Redis.from_env()\n\n# for async use\nfrom redis_sdk.asyncio import Redis\nredis = Redis.from_env()\n```\n\nIf you are in a serverless environment that allows it, it's recommended to initialise the client outside the request handler\nto be reused while your function is still hot.\n\nRunning commands might look like this:\n\n```python\nfrom redis_sdk import Redis\n\nredis = Redis.from_env()\n\ndef main():\n  redis.set(\"a\", \"b\")\n  print(redis.get(\"a\"))\n\n# or for async context:\n\nfrom redis_sdk.asyncio import Redis\n\nredis = Redis.from_env()\n\nasync def main():  \n  await redis.set(\"a\", \"b\")\n  print(await redis.get(\"a\"))\n```\n\n### BITFIELD and BITFIELD_RO\nOne particular case is represented by these two chained commands, which are available as functions that return an instance of \nthe `BITFIELD` and, respectively, `BITFIELD_RO` classes. Use the `execute` function to run the commands.\n\n```python\nredis.bitfield(\"test_key\") \\\n  .incrby(encoding=\"i8\", offset=100, increment=100) \\\n  .overflow(\"SAT\") \\\n  .incrby(encoding=\"i8\", offset=100, increment=100) \\\n  .execute()\n\nredis.bitfield_ro(\"test_key_2\") \\\n  .get(encoding=\"u8\", offset=0) \\\n  .get(encoding=\"u8\", offset=\"#1\") \\\n  .execute()\n```\n\n### Custom commands\nIf you want to run a command that hasn't been implemented, you can use the `execute` function of your client instance\nand pass the command as a `list`.\n\n```python\nredis.execute(command=[\"XLEN\", \"test_stream\"])\n```\n\n# Encoding\nAlthough Redis can store invalid JSON data, there might be problems with the deserialization.\nTo avoid this, the Khulnasoft REST proxy is capable of encoding the data as base64 on the server and then sending it to the client to be\ndecoded. \n\nFor very large data, this can add a few milliseconds in latency. So, if you're sure that your data is valid JSON, you can set\n`rest_encoding` to `None`.\n\n# Retry mechanism\nredis-sdk has a fallback mechanism in case of network or API issues. By default, if a request fails it'll retry once, 3 seconds \nafter the error. If you want to customize that, set `rest_retries` and `rest_retry_interval` (in seconds).\n\n# Contributing\n\n## Preparing the environment\nThis project uses [Poetry](https://python-poetry.org) for packaging and dependency management. Make sure you are able to create the poetry shell with relevant dependencies.\n\nYou will also need a database on [Khulnasoft](https://console.khulnasoft.com/).\n\n## Running tests\nTo run all the tests, make sure the poetry virtual environment activated with all \nthe necessary dependencies. Set the `REDIS_SDK_REST_URL` and `REDIS_SDK_REST_TOKEN` environment variables and run:\n\n```bash\npoetry run pytest\n```",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Serverless Redis SDK from Khulnasoft",
    "version": "1.0.0",
    "project_urls": {
        "Homepage": "https://github.com/khulnasoft-lab/redispy",
        "Repository": "https://github.com/khulnasoft-lab/redispy"
    },
    "split_keywords": [
        "khulnasoft redis",
        "serverless redis"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "808a48a46a0c3851bdee7fb03c4d7fb4dfc434e896acd1e29f2a6b61b0291942",
                "md5": "d7e71a40d103bde8ff1998f6d5c783fd",
                "sha256": "fefb4c54a9362f678a41d071d4bda5e2e9b7a337f9155f9ec782110a4bd8ac4b"
            },
            "downloads": -1,
            "filename": "redis_sdk-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d7e71a40d103bde8ff1998f6d5c783fd",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 31703,
            "upload_time": "2023-12-09T02:25:43",
            "upload_time_iso_8601": "2023-12-09T02:25:43.591169Z",
            "url": "https://files.pythonhosted.org/packages/80/8a/48a46a0c3851bdee7fb03c4d7fb4dfc434e896acd1e29f2a6b61b0291942/redis_sdk-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "be37a5e7161cb4f0211139d7f7b3fecdd3f6b13c621ec91668c0e4b55608776c",
                "md5": "623646095e01885ea35764dc743375e2",
                "sha256": "b668087136bf053b799b26968eeb7ba4e1bb58a0438dac2a7be7ef96435ce50e"
            },
            "downloads": -1,
            "filename": "redis_sdk-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "623646095e01885ea35764dc743375e2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 29834,
            "upload_time": "2023-12-09T02:25:46",
            "upload_time_iso_8601": "2023-12-09T02:25:46.249481Z",
            "url": "https://files.pythonhosted.org/packages/be/37/a5e7161cb4f0211139d7f7b3fecdd3f6b13c621ec91668c0e4b55608776c/redis_sdk-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-09 02:25:46",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "khulnasoft-lab",
    "github_project": "redispy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "redis-sdk"
}
        
Elapsed time: 0.50236s