Skip to main content

Python async client for Redis key-value store

Project description

coredis

docs codecov Latest Version in PyPI ci Supported Python versions


coredis is an async redis client with support for redis server, cluster & sentinel.

  • The client API uses the specifications in the Redis command documentation to define the API by using the following conventions:

    • Arguments retain naming from redis as much as possible
    • Only optional variadic arguments are mapped to variadic positional or keyword arguments. When the variable length arguments are not optional (which is almost always the case) the expected argument is an iterable of type Parameters or Mapping.
    • Pure tokens used as flags are mapped to boolean arguments
    • One of arguments accepting pure tokens are collapsed and accept a PureToken
  • Responses are mapped between RESP and python types as closely as possible.

  • For higher level concepts such as Pipelines, LUA Scripts, PubSub & Streams abstractions are provided to encapsulate recommended patterns. See the Handbook and the API Documentation for more details.

Warning The command API does NOT mirror the official python redis client. For details about the high level differences refer to Divergence from aredis & redis-py


Installation

To install coredis:

$ pip install coredis

Feature Summary

Deployment topologies

Application patterns

Server side scripting

Redis Modules

Miscellaneous

Quick start

Single Node or Cluster client

import asyncio
from coredis import Redis, RedisCluster

async def example():
    client = Redis(host='127.0.0.1', port=6379, db=0)
    # or with redis cluster
    # client = RedisCluster(startup_nodes=[{"host": "127.0.01", "port": 7001}])
    await client.flushdb()
    await client.set('foo', 1)
    assert await client.exists(['foo']) == 1
    assert await client.incr('foo') == 2
    assert await client.incrby('foo', increment=100) == 102
    assert int(await client.get('foo')) == 102

    assert await client.expire('foo', 1)
    await asyncio.sleep(0.1)
    assert await client.ttl('foo') == 1
    assert await client.pttl('foo') < 1000
    await asyncio.sleep(1)
    assert not await client.exists(['foo'])

asyncio.run(example())

Sentinel

import asyncio
from coredis.sentinel import Sentinel

async def example():
    sentinel = Sentinel(sentinels=[("localhost", 26379)])
    primary = sentinel.primary_for("myservice")
    replica = sentinel.replica_for("myservice")

    assert await primary.set("fubar", 1)
    assert int(await replica.get("fubar")) == 1

asyncio.run(example())

To see a full list of supported redis commands refer to the Command compatibility documentation

Details about supported Redis modules and their commands can be found here

Compatibility

coredis is tested against redis versions 6.2.x, 7.0.x & 7.2.x. The test matrix status can be reviewed here

coredis is additionally tested against:

  • uvloop >= 0.15.0

Supported python versions

  • 3.8
  • 3.9
  • 3.10
  • 3.11
  • PyPy 3.8
  • PyPy 3.9

Redis-like backends

coredis is known to work with the following databases that have redis protocol compatibility:

References

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coredis-4.17.0.tar.gz (243.2 kB view hashes)

Uploaded Source

Built Distributions

coredis-4.17.0-py3-none-any.whl (239.7 kB view hashes)

Uploaded Python 3

coredis-4.17.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (357.3 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

coredis-4.17.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (353.8 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

coredis-4.17.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (360.9 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

coredis-4.17.0-cp312-cp312-macosx_11_0_arm64.whl (327.7 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

coredis-4.17.0-cp312-cp312-macosx_10_9_x86_64.whl (330.5 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

coredis-4.17.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (355.5 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

coredis-4.17.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (352.7 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

coredis-4.17.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (358.7 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

coredis-4.17.0-cp311-cp311-macosx_11_0_arm64.whl (328.1 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

coredis-4.17.0-cp311-cp311-macosx_10_9_x86_64.whl (330.7 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

coredis-4.17.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (357.7 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

coredis-4.17.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (354.4 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

coredis-4.17.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (361.0 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

coredis-4.17.0-cp310-cp310-macosx_11_0_arm64.whl (330.2 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

coredis-4.17.0-cp310-cp310-macosx_10_9_x86_64.whl (332.4 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

coredis-4.17.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (357.6 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

coredis-4.17.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (354.2 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

coredis-4.17.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (361.0 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

coredis-4.17.0-cp39-cp39-macosx_11_0_arm64.whl (330.2 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

coredis-4.17.0-cp39-cp39-macosx_10_9_x86_64.whl (332.3 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

coredis-4.17.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (356.6 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

coredis-4.17.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (353.5 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

coredis-4.17.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (360.6 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

coredis-4.17.0-cp38-cp38-macosx_11_0_arm64.whl (328.6 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

coredis-4.17.0-cp38-cp38-macosx_10_9_x86_64.whl (330.5 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

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