psd-tools is a Python package designed for working with Adobe Photoshop PSD and PSB files, enabling reading, writing, and manipulation of layer data and compositions. The current version is 1.15.0.post1, and it maintains an active release cadence with frequent updates and improvements. It provides functionalities for low-level file structure access, raw layer image export, and limited layer composition.
pip install psd-toolsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to open a PSD file, composite the entire image, and then iterate through its layers, saving each visible pixel layer as a separate PNG. Ensure you have an 'example.psd' file available for the code to run successfully.
If using advanced features, install with `pip install 'psd-tools[composite]'` or install dependencies individually: `pip install psd-tools aggdraw scipy scikit-image`.
Use methods like `psdimage.create_pixel_layer(image, name="Layer 1")` for layer creation, ensuring a `PSDImage` context.
Replace calls to `compose()` with `composite()`.
To iterate from foreground to background (like older versions or Photoshop's layer panel), use `reversed(psd_image_object)`.
Be aware of this limitation; for exact Photoshop rendering, you may need to rely on Photoshop itself or check for updates to `psd-tools` that expand rendering support.
Ensure your Pillow installation has LITTLECMS/LITTLECMS2 support. This often requires installing development headers before installing Pillow, or using pre-built wheels that include it.
Install the optional dependencies: `pip install 'psd-tools[composite]'`
Consult the `psd-tools` documentation or GitHub issues to check for specific layer type support. If unsupported, you may need to access lower-level PSD structures or consider alternative methods for these specific properties.
Verify the integrity of the PSD file. Try opening it in Photoshop to see if it's recoverable. If not, you might need a backup of the PSD or specialized PSD repair tools.
For these layer types, `layer.composite()` might return `None` or an incomplete image. If direct pixel access is needed, ensure the PSD is saved with 'Maximize Compatibility' in Photoshop, which embeds a composite image.