Skip to content

alisaifee/memcachio

Folders and files

NameName
Last commit message
Last commit date
Apr 9, 2025
Apr 17, 2025
Apr 17, 2025
Apr 18, 2025
Mar 31, 2025
Apr 17, 2025
Mar 31, 2025
Mar 31, 2025
Mar 31, 2025
Mar 31, 2025
Apr 17, 2025
Mar 31, 2025
Mar 31, 2025
Mar 31, 2025
Apr 1, 2025
Apr 17, 2025
Mar 31, 2025
Mar 31, 2025
Apr 21, 2025
Apr 4, 2025
Apr 9, 2025
Mar 31, 2025

Repository files navigation

memcachio

docs codecov Latest Version in PyPI ci Supported Python versions


A pure python async Memcached client with 0 dependencies with support for:

  • All memcached commands
  • Memcached servers serving on TCP or Unix Domain Sockets
  • Memcached clusters
  • SSL transport
  • SASL Authentication
  • Connection reuse for multiple concurrent requests
  • Dynamically adjusted connection pooling
  • Auto discovery with AWS ElastiCache

Installation

To install memcachio:

$ pip install memcachio

Quick start

Single Node or Cluster client

import asyncio

from memcachio import Client


async def example() -> None:

    #: basic client
    raw_client = Client(("localhost", 11211))
    #: client that decodes the byte responses
    decoding_client = Client(("localhost", 11211), decode_responses=True)
    # or with a cluster
    # cluster_client = Client([("localhost", 11211), ("localhost", 11212)], decode_responses=True)

    await raw_client.flushall()
    await raw_client.set("foo", b"1")
    await raw_client.set("bar", b"2")

    assert 2 == await raw_client.incr("foo", 1)

    # use the raw client to get a value.
    # Note the mapping returned has byte keys
    assert (await raw_client.get("foo")).get(b"foo").value == b"2"

    # get the values with the decoding client and touch their expiry to be 1 second.
    # Note the mapping and the values are strings.
    gat_and_touch_many = await decoding_client.gat("foo", "bar", expiry=1)
    assert ["2", "2"] == [item.value for item in gat_and_touch_many.values()]

    await asyncio.sleep(1)

    assert {} == await decoding_client.get("foo", "bar")


asyncio.run(example())

See Client for detailed descriptions of available options when constructing a client.

Compatibility

memcachio is tested against memcached versions 1.6.x

Supported python versions

  • 3.10
  • 3.11
  • 3.12
  • 3.13
  • PyPy 3.10
  • PyPy 3.11

References