{"id":7476,"library":"openslide-python","title":"OpenSlide Python","description":"OpenSlide Python provides a Python interface to the OpenSlide C library, which is designed for reading high-resolution whole-slide images (WSI) commonly used in digital pathology. These images, often gigapixels in size, are too large for standard image processing libraries, so OpenSlide offers efficient multi-resolution access. The current version is 1.4.3, and the project maintains a regular release cadence with frequent updates.","status":"active","version":"1.4.3","language":"python","source_language":"en","source_url":"https://github.com/openslide/openslide-python","tags":["microscopy","pathology","image processing","WSI","whole-slide-imaging","digital-pathology"],"install":[{"cmd":"pip install openslide-python openslide-bin","lang":"bash","label":"Recommended (Python bindings + OpenSlide C library)"},{"cmd":"pip install openslide-python # If OpenSlide C library is already installed via system package manager","lang":"bash","label":"Alternative (Python bindings only)"}],"dependencies":[{"reason":"Required for image manipulation and thumbnail generation.","package":"Pillow","optional":false},{"reason":"The core C library for reading whole-slide images. The 'openslide-bin' package provides pre-compiled binaries for convenience.","package":"openslide","optional":false}],"imports":[{"symbol":"OpenSlide","correct":"from openslide import OpenSlide"},{"note":"Base exception for OpenSlide related errors.","symbol":"OpenSlideError","correct":"from openslide import OpenSlideError"},{"note":"Raised when attempting to open an unsupported or corrupt file.","symbol":"OpenSlideUnsupportedFormatError","correct":"from openslide import OpenSlideUnsupportedFormatError"}],"quickstart":{"code":"import openslide\nfrom PIL import Image\nimport os\n\n# NOTE: Replace 'path/to/your/slide.svs' with an actual whole-slide image file.\n# You might need to adjust the path if running on Windows and openslide-bin isn't used,\n# by adding the OpenSlide DLL directory to os.add_dll_directory().\n# Example for Windows (uncomment and modify if needed):\n# os.add_dll_directory(r'C:\\path\\to\\OpenSlide\\bin')\n\nslide_path = os.environ.get('OPENSLIDE_TEST_SLIDE', 'path/to/your/slide.svs')\n\ntry:\n    with openslide.OpenSlide(slide_path) as slide:\n        print(f\"Slide dimensions (level 0): {slide.dimensions}\")\n        print(f\"Number of levels: {slide.level_count}\")\n        print(f\"Vendor: {slide.properties.get(openslide.PROPERTY_NAME_VENDOR, 'Unknown')}\")\n        print(f\"Objective Power: {slide.properties.get(openslide.PROPERTY_NAME_OBJECTIVE_POWER, 'Unknown')}\")\n\n        # Get a thumbnail (e.g., max 200x200 pixels)\n        thumbnail: Image.Image = slide.get_thumbnail((200, 200))\n        # thumbnail.save('thumbnail.png')\n        print(f\"Generated thumbnail with size: {thumbnail.size}\")\n\n        # Read a region at a specific level (e.g., 512x512 pixels at level 2)\n        # region: Image.Image = slide.read_region((0, 0), 2, (512, 512))\n        # region.save('region_level2.png')\n\nexcept openslide.OpenSlideError as e:\n    print(f\"Error opening slide: {e}\")\nexcept FileNotFoundError:\n    print(f\"Error: Slide file not found at '{slide_path}'\")\n","lang":"python","description":"This quickstart demonstrates how to open a whole-slide image, access its basic properties (dimensions, level count, vendor, objective power), and generate a thumbnail image using the `OpenSlide` object. It includes error handling for common issues like file not found or unsupported formats."},"warnings":[{"fix":"Upgrade Python environment to 3.10 or later.","message":"Python 3.9 support was dropped in openslide-python 1.4.3, 3.8 in 1.4.2, and 3.7 in 1.3.0. Users must upgrade to Python 3.10 or newer.","severity":"breaking","affected_versions":">=1.3.0"},{"fix":"Ensure the OpenSlide C library is installed. Use `pip install openslide-bin` or install via your system's package manager (e.g., `apt`, `dnf`, `macports`, `conda`). Refer to the official OpenSlide documentation for detailed installation instructions for your OS.","message":"OpenSlide Python is a wrapper for the OpenSlide C library, which must be installed separately. While `pip install openslide-bin` simplifies this, it may not cover all platforms or complex system setups. Failure to install the C library will lead to import errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Before `import openslide`, add `os.add_dll_directory(r'C:\\path\\to\\openslide-win64\\bin')` (replace with your actual path to the OpenSlide binaries).","message":"On Windows, if the OpenSlide C library DLLs are not found in standard system paths or provided by `openslide-bin`, you may need to explicitly add their directory to the DLL search path using `os.add_dll_directory()` before importing `openslide`.","severity":"gotcha","affected_versions":"All versions on Windows"},{"fix":"Standardize on a single installation method. For example, use `pip install openslide-python openslide-bin` for both, or install both through a single system package manager like `conda`.","message":"Mixing OpenSlide (C library) and OpenSlide Python installations from different package managers (e.g., OpenSlide from MacPorts and OpenSlide Python from Anaconda) can lead to library conflicts and unexpected behavior.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'1.4.3':58 'access':53 'c':12 'cadenc':66 'common':27 'current':55 'design':16 'digit':30,80 'digital-patholog':79 'effici':49 'frequent':68 'gigapixel':35 'high':20 'high-resolut':19 'imag':25,33,43,72,78 'interfac':8 'larg':40 'librari':13,45 'maintain':62 'microscopi':70 'multi':51 'multi-resolut':50 'offer':48 'often':34 'openslid':1,3,11,47 'patholog':31,71,81 'process':44,73 'project':61 'provid':5 'python':2,4,7 'read':18 'regular':64 'releas':65 'resolut':21,52 'size':37 'slide':24,77 'standard':42 'updat':69 'use':28 'version':56 'whole':23,76 'whole-slid':22 'whole-slide-imag':75 'wsi':26,74","created_at":"2026-04-16T13:59:56.733264+00:00","updated_at":"2026-04-16T13:59:56.733264+00:00","problems":{"verify_error":"error: Failed to parse: `openslide-python openslide-bin`\n  Caused by: Expected one of `@`, `(`, `<`, `=`, `>`, `~`, `!`, `;`, found `o`\nopenslide-python openslide-bin\n                 ^"},"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.4.6","cli_name":"","cli_version":null,"type":"library","homepage":"https://openslide.org/","github":"https://github.com/openslide/openslide-python","docs":"https://openslide.org/api/python/","changelog":"https://github.com/openslide/openslide-python/blob/main/CHANGELOG.md","pypi":"https://pypi.org/project/openslide-python/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["data","ai-ml"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"install_fail","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-05","install_tag":null}}