{"library":"python-discovery","code":"from pathlib import Path\nfrom python_discovery import DiskCache, get_interpreter\nimport os\n\n# Define a cache root path; for a quickstart, we use a demo-specific path.\n# In a real application, consider a persistent user cache (e.g., ~/.cache/python-discovery).\ncache_root = Path.home() / \".cache\" / \"python-discovery-quickstart-demo\"\ncache_root.mkdir(parents=True, exist_ok=True)\ncache = DiskCache(root=cache_root)\n\n# Discover any Python 3 interpreter available on the system\nprint(\"Attempting to discover a Python 3.x interpreter...\")\npython_3_interpreter = get_interpreter(\"python3\", cache=cache)\n\nif python_3_interpreter:\n    print(f\"Found Python 3 interpreter: {python_3_interpreter.executable}\")\n    print(f\"Version: {python_3_interpreter.version}\")\n    print(f\"Prefix: {python_3_interpreter.prefix}\")\nelse:\n    print(\"Could not find a Python 3 interpreter.\")\n\n# Discover a specific Python version using PEP 440 specifier\nprint(\"\\nAttempting to discover Python >=3.9,<3.12...\")\nspecific_interpreter = get_interpreter(\">=3.9,<3.12\", cache=cache)\n\nif specific_interpreter:\n    print(f\"Found Python matching spec: {specific_interpreter.executable}\")\n    print(f\"Version: {specific_interpreter.version}\")\nelse:\n    print(\"Could not find a Python interpreter matching '>=3.9,<3.12'.\")\n","lang":"python","description":"This quickstart demonstrates how to use `get_interpreter` to find Python installations based on version specifiers, leveraging `DiskCache` for performance. It attempts to find any Python 3 interpreter and then a specific range of Python 3 versions.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}