Skip to main content

Introduction to bmemcached

A pure python module (thread safe) to access memcached via it’s binary with SASL auth support.

The main purpose of this module it to be able to communicate with memcached using binary protocol and support authentication, so it can work with Heroku for example.

Latest compiled docs on Read The Docs here.

Installing

Use pip or easy_install.

pip install python-binary-memcached

Using

import bmemcached
client = bmemcached.Client(('127.0.0.1:11211', ), 'user',
                            'password')
client.set('key', 'value')
print(client.get('key'))

Using it with distributed keys

import bmemcached
client = bmemcached.DistributedClient(
    ('127.0.0.1:11211', ), 'user', 'password'
)
client.set('key', 'value')
print(client.get('key'))

Using it with raw data

By default, the client keeps the type of each value in the memcached flags field. Some applications already use the flags field for their own data, and a default client then fails to read their keys. Set raw_data=True to read and write those keys.

import bmemcached
client = bmemcached.Client(('127.0.0.1:11211', ), raw_data=True)
client.set('key', b'value')
print(client.get('key'))  # b'value'

In raw data mode:

  • A read returns the stored bytes value. The client ignores the flags field.

  • A write accepts only bytes values. Other types raise TypeError.

  • The client does not compress values. The default compress_level=-1 means no compression, and a compress_level greater than 0 raises MemcachedException.

DistributedClient accepts the same raw_data argument.

Testing

python-binary-memcached unit tests are found in the test/ directory and are designed to be run using pytest. pytest will discover the tests automatically, so all you have to do is:

$ pytest
...
170 passed in 4.43 seconds

This runs the tests with the default Python interpreter.

You can also verify that the tests pass on other supported Python interpreters. For this we use tox, which will automatically create a virtualenv for each supported Python version and run the tests. For example:

$ tox
...
py310: commands succeeded
py311: commands succeeded
py312: commands succeeded
ERROR:  py313: InterpreterNotFound: python3.13
py314: commands succeeded

You may not have all the required Python versions installed, in which case you will see one or more InterpreterNotFound errors.

Using with Django

If you want to use it with Django, go to django-bmemcached to get a Django backend.

Tests Status

https://github.com/jaysonsantos/python-binary-memcached/actions/workflows/tests-and-lint.yml/badge.svg?branch=main

v0.33.0 (2026-10-12)

Feat

  • add raw_data mode to skip value serialization (#315)

  • set the Python 3.10 floor and remove the Python 2 support layer (#278)

Fix

  • remove the per-call struct format strings from the response parse path (#286)

  • show the password state in Protocol.__str__

  • keep distributed hash ring placement

  • replace assert guards, add an exception message, and stop a password leak

  • Minor performance improvements in hot paths (#263)

v0.32.0 (2026-04-28)

Docs

  • Add repository contribution guidelines.

v0.31.2 (2022-12-14)

Fix

  • Remove setup’s.py dependency on m2r

v0.31.1 (2021-12-29)

v0.31.0 (2021-12-28)

Refactor

  • Use bytearrays for building up bytes for I/O. (#245)

Feat

  • Expose incr/decr default and time protocol arguments in client class (#243)

v0.30.1 (2020-10-11)

v0.30.0 (2020-08-18)

  • Add ability to return default value on get but breaking get’s API

  • Support an arbitrary collection of keys, not just a list

v0.30 (2020-06-10)

v0.29.0 (2020-01-29)

  • added TLS support on #211 thanks to @moisesguimaraes!

v0.28.0 (2018-10-02)

  • moved bmemcached.Client to bmemcached.ReplicantClient but keeps backward compatibility

  • added DistributedClient to distribute keys over servers using consistent hashing

v0.27.0 (2018-08-10)

0.26.1 (2017-07-18)

0.26.0 (2017-01-13)

0.25.0 (2016-12-15)

0.24.7 (2016-11-08)

0.24.2 (2014-05-27)

0.24.1 (2014-05-20)

0.24 (2014-04-28)

0.23 (2014-04-18)

v0.18 (2013-05-06)

v0.17 (2013-04-15)

Metadata

Release files for python-binary-memcached 0.33.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 python-binary-memcached 0.33.0
File Size Uploaded
python_binary_memcached-0.33.0.tar.gz 109.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-binary-memcached 0.33.0
File Interpreter ABI Platform
python_binary_memcached-0.33.0-py3-none-any.whl Python 3 none any Details

Total release size: 132.3 kB

Release files / python_binary_memcached-0.33.0.tar.gz

Download URL python_binary_memcached-0.33.0.tar.gz
Size 109.6 kB
Tags Source
SHA-256 checksum
How to use checksums
032241550a64f1d1b668cd858ccb4d78a471b936eee8cdf0718af15811ae7036
BLAKE2b-256 checksum
How to use checksums
a62cd84d61605b1db1a347ea180dae0642efe7729941982391d199fb0ee8cd3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.

Transparency log

Release files / python_binary_memcached-0.33.0-py3-none-any.whl

Download URL python_binary_memcached-0.33.0-py3-none-any.whl
Size 22.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c2a3477b935f45cdd6b71a8e1a07b315aa51b25cccf03f08a545fd35515c5e6d
BLAKE2b-256 checksum
How to use checksums
87dcb839c5f2f4a8201bf22675ea61733cc4db58606549f1c8a302ec246110e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.33.0 This release

2 release files

0.32.0

2 release files

0.31.3

2 release files

0.31.2

2 release files

0.31.1

2 release files

0.30.1

2 release files

0.30.0

1 release file

0.29.0

1 release file

0.28.0

1 release file

0.27.0

1 release file

0.26.1

1 release file

0.26.0

1 release file

0.25.0

1 release file

0.24.7

1 release file

0.24.6

1 release file

0.24.5

1 release file

0.24.4

1 release file

0.24.3

1 release file

0.24.2

1 release file

0.24.1

1 release file

0.24

1 release file

0.23

1 release file

0.22

1 release file

0.21

1 release file

0.20

1 release file

0.19

1 release file

0.18

1 release file

0.17

1 release file

0.16

1 release file

0.15

1 release file

0.14

1 release file

0.13

1 release file

0.12

1 release file

0.11

1 release file

0.10

1 release file

0.9

1 release file

0.8

1 release file

0.7

1 release file

0.6

1 release file

0.5

1 release file

0.4

1 release file

0.3

1 release file

0.2

1 release file

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