Registry /
database / python-binary-memcached
Install & Compatibility
Where this runs
tested against v0.32.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.064s · 18.2MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 1.6s · import 0.060s · 19MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Client
✓ from bmemcached import Client
✗ import bmemcached.Client
The primary client for interacting with a single or failover Memcached setup.
DistributedClient
✓ from bmemcached import DistributedClient
A client for distributing keys across multiple Memcached servers using consistent hashing.
Initializes a `bmemcached.Client` instance, sets a string value, retrieves it, and then deletes it. Ensure a Memcached server is running at `127.0.0.1:11211`.
import bmemcached
import os
# Configure client with Memcached server address, optional username, and password
# Use environment variables for sensitive information
servers = ['127.0.0.1:11211']
username = os.environ.get('MEMCACHED_USER', '')
password = os.environ.get('MEMCACHED_PASSWORD', '')
mc = bmemcached.Client(servers, username, password)
# Set a key-value pair
mc.set('my_key', 'Hello, Memcached!')
print(f"Set 'my_key': {mc.get('my_key')}")
# Get a key-value pair
value = mc.get('my_key')
if value:
print(f"Retrieved 'my_key': {value.decode('utf-8')}")
else:
print("'my_key' not found")
# Delete a key
mc.delete('my_key')
print(f"Deleted 'my_key'. Now 'my_key' is: {mc.get('my_key')}")
Debug
Known issues
gotchaSASL authentication requires the `pysasl` library, which is an optional dependency. If you use SASL and encounter errors like `AttributeError: 'NoneType' object has no attribute 'init_client'` or `SASL error: -4`, `pysasl` is likely missing.fixInstall `pysasl` manually via `pip install pysasl` or use the extra: `pip install python-binary-memcached[sasl]`.
affects: All versions when using SASL
gotchaFor distributing keys across multiple Memcached servers using consistent hashing, explicitly use `bmemcached.DistributedClient`. While `bmemcached.Client` can take multiple servers, it primarily uses a failover strategy (it's internally a `ReplicantClient` since v0.28.0) rather than distributing keys.fixIf consistent hashing is desired for load balancing and distribution, instantiate `bmemcached.DistributedClient` instead of `bmemcached.Client`.
affects: v0.28.0 and later
gotchaTLS support was added in v0.29.0. To establish a secure connection, you must explicitly pass `tls_params` to the client constructor. Connections made without `tls_params` will not be encrypted.fixWhen initializing `Client`, pass a dictionary to the `tls_params` argument, e.g., `tls_params={'ca_certs': 'path/to/ca.pem'}`. affects: Pre-v0.29.0 behavior, relevant for v0.29.0+
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'bmemcached'
The `python-binary-memcached` library is not installed in your current Python environment.
fixRun `pip install python-binary-memcached` to install the library.
AttributeError: 'NoneType' object has no attribute 'init_client' (during client initialization with SASL) OR SASL error: -4 (SASL not initialized)
The `pysasl` library, an optional dependency required for SASL authentication, is not installed.
fixInstall the `pysasl` library: `pip install pysasl` or `pip install python-binary-memcached[sasl]`.
socket.error: [Errno 111] Connection refused OR ConnectionError: [Errno 111] Connection refused
The Memcached server is either not running, not accessible at the specified host/port, or a firewall is blocking the connection.
fixVerify that your Memcached server is running, listening on the correct IP address and port (e.g., `127.0.0.1:11211`), and that no firewall rules are preventing your application from connecting.
Upgrade
Version history
0.32.0latest on PyPI · released Apr 28, 2026
Audit
Dependencies
No dependency data recorded yet.