Registry / database / python-binary-memcached

python-binary-memcached

JSON →
library0.32.0pypypi✓ verified 87d ago

A pure Python module for accessing Memcached servers using the binary protocol, including support for SASL authentication and TLS. The current version is 0.31.4, with releases occurring periodically to add features and improvements.

pip install python-binary-memcached
INSTALL
IMPORT
SIG · PYTHON-BINARY-MEMC
P
python-binary-memcached
databasepythonv0.32.0
Install
1.6s avg
Import
62ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.064s · 18.2MB
glibc
py 3.103.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.
fix
Install `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.
fix
If 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.
fix
When 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.
fix
Run `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.
fix
Install 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.
fix
Verify 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.

Agent activity
22 hits · last 30 days
node
20
OpenAI (training)
1
Resources
python-binary-memcached — pip install python-binary-memcached · libregistry