{"id":9440,"library":"aiomcache","title":"aiomcache","description":"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.","status":"active","version":"0.8.2","language":"en","source_language":"en","source_url":"https://github.com/aio-libs/aiomcache/","tags":["async","asyncio","memcached","cache","aio-libs"],"install":[{"cmd":"pip install aiomcache","lang":"bash","label":"Install aiomcache"}],"dependencies":[],"imports":[{"symbol":"Client","correct":"from aiomcache import Client"},{"note":"Introduced in v0.8.0 for memcached flags.","symbol":"FlagClient","correct":"from aiomcache import FlagClient"}],"quickstart":{"code":"import asyncio\nimport os\nfrom aiomcache import Client\n\nasync def main():\n    # Connect to memcached using environment variables or fallbacks\n    host = os.environ.get('MEMCACHED_HOST', '127.0.0.1')\n    port = int(os.environ.get('MEMCACHED_PORT', '11211'))\n    \n    # Initialize the client (Client itself is not an awaitable)\n    mc = Client(host, port)\n    \n    key = b\"my_async_key\"\n    value = b\"my_async_value\"\n\n    try:\n        # Set a key-value pair\n        await mc.set(key, value)\n        print(f\"Set '{key.decode()}'\")\n\n        # Get the value for the key\n        retrieved_value = await mc.get(key)\n        if retrieved_value:\n            print(f\"Retrieved '{key.decode()}': '{retrieved_value.decode()}'\")\n        else:\n            print(f\"Key '{key.decode()}' not found.\")\n\n        # Delete the key\n        await mc.delete(key)\n        print(f\"Deleted '{key.decode()}'\")\n        \n    except Exception as e:\n        print(f\"An error occurred: {e}\")\n    finally:\n        # Always close the client connection(s)\n        await mc.close()\n        print(\"Client closed.\")\n\nif __name__ == \"__main__\":\n    asyncio.run(main())","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade your Python environment to 3.4 or higher. The current version (0.8.2) requires Python >= 3.8.","message":"Python 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.","severity":"breaking","affected_versions":">=0.6.0"},{"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.","message":"Prior 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.","severity":"gotcha","affected_versions":">=0.8.0"},{"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.","message":"Versions 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.","severity":"gotcha","affected_versions":"<0.5.2"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"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.","cause":"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.","error":"aiomcache.exceptions.ClientException: Cannot connect to memcached: [Errno 111] Connection refused"},{"fix":"Initialize the client directly without `await`: `mc = Client(host, port)`. Then, `await` its methods like `await mc.set(...)` or `await mc.get(...)`.","cause":"The `aiomcache.Client` class itself is not an awaitable object. Only its asynchronous methods (e.g., `set`, `get`, `delete`, `close`) should be awaited.","error":"TypeError: object Client can't be used in 'await' expression"},{"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: ...`","cause":"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.","error":"TypeError: 'NoneType' object is not subscriptable"}]}