Skip to main content

django-elastipymemcache

codecov

Overview

django-elastipymemcache is a Django cache backend for Amazon ElastiCache (memcached) clusters. It is built on top of pymemcache and connects to all cluster nodes via ElastiCache Auto Discovery.

Originally forked from django-elasticache, this implementation adds:

  • Thread-safe topology updates (atomic swaps)
  • Auto discovery for scaling events
  • Connection pooling (data nodes & config endpoint)
  • Optional TLS connectivity
  • Compatibility with Django’s cache interface

Requirements

  • Python >= 3.10
  • Django >= 4.2
  • pymemcache >= 4.0.0

Installation

Get it from PyPI:

python3 -m pip install django-elastipymemcache

Usage

Basic

CACHES = {
    "default": {
        "BACKEND": "django_elastipymemcache.backend.ElastiPymemcache",
        "LOCATION": "[configuration-endpoint]:11211",
        "OPTIONS": {
            "ignore_exc": True,
        },
    }
}

Connection Pooling

CACHES = {
    "default": {
        "BACKEND": "django_elastipymemcache.backend.ElastiPymemcache",
        "LOCATION": "[configuration-endpoint]:11211",
        "OPTIONS": {
            # Enable pooling for both config endpoint and data nodes
            "use_pooling": True,
            "pool_idle_timeout": 30,
            "connect_timeout": 0.3,
            "timeout": 0.5,
            "ignore_exc": True,
        },
    }
}

Auto Discovery (with pooling)

CACHES = {
    "default": {
        "BACKEND": "django_elastipymemcache.backend.ElastiPymemcache",
        "LOCATION": "[configuration-endpoint]:11211",
        "OPTIONS": {
            "use_pooling": True,
            "discovery_interval": 60.0,
            "discovery_retry_delay": 2.0,
            "ignore_exc": True,
        },
    }
}

Options

The backend accepts a combination of ElastiPymemcache-specific options and pymemcache client options. For the complete list of pymemcache options, see: https://pymemcache.readthedocs.io/

ElastiPymemcache-specific options

Option Type Default Description
discovery_interval float 0.0 Periodic auto-discovery interval in seconds. Set 0.0 to disable.
discovery_retry_delay float 0.0 Delay (seconds) before retrying discovery after failure.
use_vpc_ip_address bool True Prefer VPC private IPs over DNS hostnames (recommended on AWS).

Notes

  • According to the official Amazon ElastiCache documentation, auto-discovery must be enabled to support vertical scaling. https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/Scaling-self-designed.mem-heading.html
  • Auto-discovery also runs on demand when the ring is empty, even if discovery_interval is 0.0. It runs at most once per discovery_retry_delay (1 second if unset), and lookups do not wait for a discovery that is already running. This helps recover after scale events or a failed initial discovery.
  • If you use TLS, pass the appropriate tls_context through OPTIONS (this is a pymemcache option) and ensure your ElastiCache cluster supports TLS.
  • When use_pooling is enabled, the client and its connection pools are shared per process and reused across requests.
  • max_pool_size limits concurrent commands per process per node. Exceeding it raises RuntimeError instead of waiting (a cache miss with ignore_exc=True), so leave it unset unless needed.
  • Without use_pooling, Django 5.0 to 6.0 under ASGI leaves connections open until garbage collection.

Notice

Datadog ddtrace & pymemcache instrumentation (temporary workaround)

When using ddtrace with Django or other frameworks, enabling the pymemcache integration may trigger runtime errors such as:

ValueError: wrapper has not been initialized

This issue occurs due to wrapt interfering with class initialization order inside ddtrace’s pymemcache integration. Until Datadog releases a fix, disable the pymemcache tracer.

Environment variable

DD_TRACE_PYMEMCACHE_ENABLED=false

Code-level patch

patch_all(pymemcache=False)

Metadata

Release files for django-elastipymemcache 3.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-elastipymemcache 3.1.0
File Size Uploaded Provenance Actions
django_elastipymemcache-3.1.0.tar.gz 16.3 kB Without provenance Details for django_elastipymemcache-3.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-elastipymemcache 3.1.0
File Interpreter ABI Platform Actions
django_elastipymemcache-3.1.0-py3-none-any.whl Python 3 none any Details for django_elastipymemcache-3.1.0-py3-none-any.whl

Total release size: 26.0 kB

Release files / django_elastipymemcache-3.1.0.tar.gz

Download URL django_elastipymemcache-3.1.0.tar.gz
Size 16.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d121156a40ff0f249f9dc3574b3166c3d1dfd0cfd210420632fd5d6ebf7d881b
BLAKE2b-256 checksum
How to use checksums
c2cdb79735b2a45d801d0867aba32fd6c85a7b9db1922c2ae28a7ecf02d8d801
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / django_elastipymemcache-3.1.0-py3-none-any.whl

Download URL django_elastipymemcache-3.1.0-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
72b012072e7bad51af1e0f0cce9293fbe4c16b30f572b1741439edd5dcac69dc
BLAKE2b-256 checksum
How to use checksums
9487d6bbd70a9a66f98437404571113ed0da7b8d4e3c57e324c9a4777cd472bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for django-elastipymemcache 3.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page