A pure python module to access memcached via its binary protocol with SASL auth support
Maintained. Last release 7 weeks ago, commits in 6 of the last 26 weeks. Weaker on release cadence and contributor spread.
$
pip install python-binary-memcachedIntroduction 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 <https://python-binary-memcached.readthedocs.org>`_.
Installing
----------
Use pip or easy_install.
.. code-block:: bash
pip install python-binary-memcached
Using
-----
.. code-block:: python
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
.. code-block:: python
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.
.. code-block:: python
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.
.. warning::
A write in raw data mode sets the flags field of the key to 0. This
overwrites the flags that another application set on the key.
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:
.. code-block:: console
$ 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:
.. code-block:: console
$ 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 <https://github.com/jaysonsantos/django-bmemcached>`_ to get a Django backend.
Tests Status
------------
.. image:: https://github.com/jaysonsantos/python-binary-memcached/actions/workflows/tests-and-lint.yml/badge.svg?branch=main
:target: https://github.com/jaysonsantos/python-binary-memcached/actions/workflows/tests-and-lint.yml
.. _`pytest`: https://pypi.org/project/pytest/
.. _`tox`: https://pypi.org/project/tox/
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-1:
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-1:
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)
===================
.. _section-1:
0.26.0 (2017-01-13)
===================
.. _section-2:
0.25.0 (2016-12-15)
===================
.. _section-3:
0.24.7 (2016-11-08)
===================
.. _section-4:
0.24.2 (2014-05-27)
===================
.. _section-5:
0.24.1 (2014-05-20)
===================
.. _section-6:
0.24 (2014-04-28)
=================
.. _section-7:
0.23 (2014-04-18)
=================
v0.18 (2013-05-06)
==================
v0.17 (2013-04-15)
==================