Registry / database / python-binary-memcached

python-binary-memcached

JSON →
library0.31.4pypypi✓ verified 35d 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.

databasehttp-networkingauth-security
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.

The primary client for interacting with a single or failover Memcached setup.

from bmemcached import Client

A client for distributing keys across multiple Memcached servers using consistent hashing.

from bmemcached import DistributedClient

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 footguns
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.
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.
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.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
17 hits · last 30 days
gptbot
4
ahrefsbot
4
dotbot
3
script
1
bytedance
1
Resources