{"id":4780,"library":"standard-imghdr","title":"Standard imghdr Library","description":"The `standard-imghdr` library is a redistribution of the `imghdr` module, which was formerly part of the Python standard library. It provides functionality to determine the type of an image file based on its header. Maintained by the `python-deadlib` project, this library serves as a compatibility layer for projects that relied on `imghdr` after its deprecation in Python 3.11 and subsequent removal in Python 3.13. The current version is 3.13.0 and it follows an infrequent release cadence focused on maintaining compatibility.","status":"maintenance","version":"3.13.0","language":"en","source_language":"en","source_url":"https://github.com/youknowone/python-deadlib","tags":["image","compatibility","deprecated","standard library","utility"],"install":[{"cmd":"pip install standard-imghdr","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"note":"The original module and this redistribution are typically imported as a whole, then functions like `what` are accessed via `imghdr.what()`.","wrong":"from imghdr import what","symbol":"imghdr","correct":"import imghdr"}],"quickstart":{"code":"import imghdr\nimport os\n\n# Create a dummy JPEG file for demonstration\ndummy_jpeg_data = b'\\xFF\\xD8\\xFF\\xE0\\x00\\x10JFIF\\x00\\x01\\x01\\x00\\x00\\x01\\x00\\x01\\x00\\x00\\xFF\\xDB\\x00C\\x00\\x08\\x06\\x06\\x07\\x06\\x05\\x08\\x07\\x07\\x07\\x09\\x09\\x08\\x0A\\x0C\\x14\\x0D\\x0C\\x0B\\x0B\\x0C\\x19\\x12\\x13\\x0F\\x14\\x1D\\x1A\\x1F\\x1E\\x1D\\x1A\\x1C\\x1C\\x20\\x24\\x2E\\x27\\x20\\x22\\x2C\\x23\\x1C\\x1C\\x28\\x37\\x29\\x2B\\x30\\x31\\x30\\x33\\x31\\x2F\\x36\\x2E\\x37\\x39\\x3D\\x3B\\x3A\\x32\\x38\\x37\\x3D\\x36\\x36\\x38\\x37\\x20\\x20'\ndummy_png_data = b'\\x89PNG\\r\\n\\x1a\\n\\x00\\x00\\x00\\rIHDR\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x01\\x08\\x06\\x00\\x00\\x00\\x1f\\x15\\xc4\\x89\\x00\\x00\\x00\\x0cIDATx\\xda\\xed\\xc1\\x01\\x01\\x00\\x00\\x00\\xc2\\xa0\\xf7Om\\x00\\x00\\x00\\x00IEND\\xaeB`\\x82'\n\n# Create temporary files\nwith open('test_image.jpg', 'wb') as f:\n    f.write(dummy_jpeg_data)\nwith open('test_image.png', 'wb') as f:\n    f.write(dummy_png_data)\n\n# Determine image type by filename\nimage_type_jpg = imghdr.what('test_image.jpg')\nprint(f\"Type of test_image.jpg: {image_type_jpg}\")\n\nimage_type_png = imghdr.what('test_image.png')\nprint(f\"Type of test_image.png: {image_type_png}\")\n\n# Determine image type from a byte stream\nimage_type_bytes = imghdr.what(None, h=dummy_jpeg_data)\nprint(f\"Type of image from bytes: {image_type_bytes}\")\n\n# Clean up temporary files\nos.remove('test_image.jpg')\nos.remove('test_image.png')","lang":"python","description":"This quickstart demonstrates how to use `imghdr.what()` to identify image types from both a filename and a byte stream. It creates temporary dummy JPEG and PNG files, identifies their types, and then cleans up the files."},"warnings":[{"fix":"For existing code, install `standard-imghdr` (`pip install standard-imghdr`). For new code, consider using more robust and actively maintained alternatives like `Pillow`, `filetype`, `puremagic`, or `python-magic`.","message":"The `imghdr` module was deprecated in Python 3.11 and completely removed from the Python standard library in Python 3.13 (PEP 594). Direct `import imghdr` will result in a `ModuleNotFoundError` in Python 3.13 and newer versions unless `standard-imghdr` is installed.","severity":"breaking","affected_versions":"Python 3.13+"},{"fix":"Avoid using `standard-imghdr` for new projects or new image handling logic. Migrate to actively maintained third-party libraries (e.g., `Pillow`, `filetype`) that offer more comprehensive and current image detection capabilities.","message":"The `standard-imghdr` library is a 'dead battery' redistribution of a removed standard library module. It is not actively developed for new features or significant improvements. The project explicitly states that it is intended for 'minimal compatibility work' only.","severity":"deprecated","affected_versions":"All versions of `standard-imghdr` (reflects the status of the original `imghdr` module)"},{"fix":"Always use virtual environments (`python -m venv .venv` followed by `source .venv/bin/activate`) when installing Python packages. If a system-wide installation is absolutely necessary and issues arise, a workaround like `pip install standard-imghdr --break-system-packages` might be needed on some systems (e.g., Arch Linux), but this is generally discouraged as it can break system Python packages.","message":"On some Linux distributions, especially when trying to install system-wide without a virtual environment, `pip install standard-imghdr` might encounter issues or recommend `pipx`, which is not suitable for libraries.","severity":"gotcha","affected_versions":"Potentially all versions, depending on Python and OS configuration."}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}