{"library":"memcache","title":"Memcache Client (PyPI `memcache`)","description":"The `memcache` library (v0.14.0) is a pure-Python client for Memcached, compatible with Python 3.7+. It is a specific fork of the original `python-memcached` project, designed for Python 3.x compatibility, and has seen sporadic updates (last updated Dec 2023). It is distinct from the `python-memcached` (v1.x.x) series, despite the PyPI `memcache` package linking its homepage to the `python-memcached` GitHub repository, causing significant confusion in the ecosystem.","language":"python","status":"active","last_verified":"Fri May 15","install":{"commands":["pip install memcache"],"cli":null},"imports":["import memcache\nmc = memcache.Client(...)"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import memcache\nimport os\nimport json\n\n# Ensure a memcached server is running, e.g., on 127.0.0.1:11211.\n# Operations will silently fail (returning None/False) if no server is reachable.\n\n# Configuration for memcached servers. Allows environment override.\nMEMCACHED_SERVERS = os.environ.get('MEMCACHED_SERVERS', '127.0.0.1:11211').split(',')\n\n# Initialize the client with best practices: binary protocol and JSON serialization.\n# This avoids pickle security issues and improves interoperability.\nmc = memcache.Client(\n    MEMCACHED_SERVERS,\n    debug=0, # Set to 1 for more verbose debugging output\n    binary=True, # Use binary protocol for better performance and features\n    serializer=json.dumps,\n    deserializer=json.loads\n)\n\nkey = \"my_test_key\"\nvalue = {\"data\": \"hello world\", \"count\": 123, \"status\": True}\n\n# Set a value, storing it for 60 seconds\nif mc.set(key, value, time=60):\n    print(f\"Set key '{key}' with value: {value}\")\nelse:\n    print(f\"Failed to set key '{key}'. Check server connection.\")\n\n# Get a value\nretrieved_value = mc.get(key)\nif retrieved_value is not None:\n    print(f\"Retrieved key '{key}': {retrieved_value}\")\nelse:\n    print(f\"Failed to retrieve key '{key}' or key not found.\")\n\n# Delete a value\nif mc.delete(key):\n    print(f\"Deleted key '{key}'.\")\nelse:\n    print(f\"Failed to delete key '{key}' or key was not present.\")\n\n# Try getting it again to confirm deletion\nretrieved_value_after_delete = mc.get(key)\nif retrieved_value_after_delete is None:\n    print(f\"Key '{key}' is confirmed deleted (returned None).\")","lang":"python","description":"This example demonstrates how to initialize the `memcache` client, set, get, and delete values. It includes recommended practices like using the binary protocol and JSON serialization to avoid common pitfalls.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-15","installed_version":"0.14.0","pypi_latest":"0.14.0","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":1.9,"avg_import_s":0.28,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"memcache","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.16,"mem_mb":5.6,"disk_size":"20.0M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"memcache","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.1,"import_time_s":0.13,"mem_mb":5.6,"disk_size":"21M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"memcache","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.25,"mem_mb":6.9,"disk_size":"21.5M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"memcache","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.9,"import_time_s":0.23,"mem_mb":6.9,"disk_size":"22M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"memcache","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.48,"mem_mb":8.2,"disk_size":"13.3M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"memcache","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.7,"import_time_s":0.42,"mem_mb":8.2,"disk_size":"14M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"memcache","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.47,"mem_mb":8.7,"disk_size":"13.1M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"memcache","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.7,"import_time_s":0.41,"mem_mb":8.7,"disk_size":"14M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"memcache","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.15,"mem_mb":5.5,"disk_size":"19.4M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"memcache","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.2,"import_time_s":0.13,"mem_mb":5.5,"disk_size":"20M"}]}}