Registry / database / aiomcache

aiomcache

JSON →
library0.8.2pypypi✓ verified 85d ago

aiomcache is a minimal pure Python memcached client built for asynchronous applications with `asyncio`. It provides an easy-to-use interface for common memcached operations like set, get, and delete. The current version is 0.8.2, and it is actively maintained within the `aio-libs` project with a moderate release cadence addressing bug fixes and minor features.

pip install aiomcache
INSTALL
IMPORT
SIG · AIOMCACHE
A
aiomcache
databasepythonv0.8.2
Install
1.5s avg
Import
213ms
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.8.2 · 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.910 runs
installs and imports cleanly · install 0.0s · import 0.227s · 18.2MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.5s · import 0.199s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Client
from aiomcache import Client
FlagClient
from aiomcache import FlagClient
Introduced in v0.8.0 for memcached flags.

This quickstart demonstrates how to initialize `aiomcache.Client`, set, get, and delete data asynchronously. It uses environment variables for host and port, falling back to localhost:11211, and includes error handling and graceful client closure.

import asyncio import os from aiomcache import Client async def main(): # Connect to memcached using environment variables or fallbacks host = os.environ.get('MEMCACHED_HOST', '127.0.0.1') port = int(os.environ.get('MEMCACHED_PORT', '11211')) # Initialize the client (Client itself is not an awaitable) mc = Client(host, port) key = b"my_async_key" value = b"my_async_value" try: # Set a key-value pair await mc.set(key, value) print(f"Set '{key.decode()}'") # Get the value for the key retrieved_value = await mc.get(key) if retrieved_value: print(f"Retrieved '{key.decode()}': '{retrieved_value.decode()}'") else: print(f"Key '{key.decode()}' not found.") # Delete the key await mc.delete(key) print(f"Deleted '{key.decode()}'") except Exception as e: print(f"An error occurred: {e}") finally: # Always close the client connection(s) await mc.close() print("Client closed.") if __name__ == "__main__": asyncio.run(main())
Debug
Known issues
breakingPython 3.3 support was dropped with the release of v0.6.0. Projects using older Python versions must upgrade to at least Python 3.4 to use aiomcache >= 0.6.0.
fix
Upgrade your Python environment to 3.4 or higher. The current version (0.8.2) requires Python >= 3.8.
affects: >=0.6.0
gotchaPrior to v0.8.0, the `Client.get()` method mistakenly used a CAS (check-and-set) operation internally. From v0.8.0 onwards, `Client.get()` correctly performs a simple GET. If your application implicitly relied on the CAS behavior of `get` (e.g., for atomicity checks), this change in behavior could be significant.
fix
Review code that uses `Client.get()` in versions < 0.8.0. If CAS-like behavior is required, explicitly use `Client.gets()` (available since v0.5.0) for versions >= 0.8.0.
affects: >=0.8.0
gotchaVersions of aiomcache prior to v0.5.2 had concurrency issues in their connection pool, which could lead to race conditions or unexpected behavior under heavy load.
fix
Upgrade to aiomcache v0.5.2 or newer to benefit from the fix for pool concurrency issues. This ensures more robust connection handling in high-concurrency environments.
affects: <0.5.2
Errors
Common errors & fixes
aiomcache.exceptions.ClientException: Cannot connect to memcached: [Errno 111] Connection refused
The memcached server is either not running, not accessible from the application's host, or configured on a different port than specified in the Client initialization.
fix
Ensure a memcached server is running and reachable on the specified `host` and `port`. Verify firewall rules or container network settings if applicable. Check the memcached server logs for issues.
TypeError: object Client can't be used in 'await' expression
The `aiomcache.Client` class itself is not an awaitable object. Only its asynchronous methods (e.g., `set`, `get`, `delete`, `close`) should be awaited.
fix
Initialize the client directly without `await`: `mc = Client(host, port)`. Then, `await` its methods like `await mc.set(...)` or `await mc.get(...)`.
TypeError: 'NoneType' object is not subscriptable
This error often occurs when attempting to access a method or element of a variable that holds `None`. In `aiomcache`, `Client.get()` returns `None` if the key does not exist in memcached, and you are trying to operate on the `None` result.
fix
Always check if the result of `Client.get()` is not `None` before attempting to decode, parse, or otherwise use it. Example: `value = await mc.get(key); if value is not None: ...`
Upgrade
Version history
0.8.2latest on PyPI · released May 7, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
46 hits · last 30 days
node
42
OpenAI (training)
2
Resources
aiomcache — pip install aiomcache · libregistry