Skip to content

loonghao/photoshop-python-api

Repository files navigation

logo

python version PyPI version Downloads Status Downloads License pypi format Chat on Discord Maintenance Bump version pages-build-deployment Documentation Status photoshop-2024 photoshop-2023 photoshop-2022 photoshop-2021 photoshop-2020 photoshop-CC2019 photoshop-CC2018 photoshop-CC2017

All Contributors

Python API for Photoshop.

⚠️ Only for Windows platform !

The example above was created with Photoshop Python API. Check it out at https://loonghao.github.io/photoshop-python-api/examples.

Has been tested and used Photoshop version:

Photoshop Version Supported
2025 βœ…
2024 βœ…
2023 βœ…
2022 βœ…
2021 βœ…
2020 βœ…
cc2019 βœ…
cc2018 βœ…
cc2017 βœ…

Installing

You can install via pip.

pip install photoshop_python_api

Since it uses COM (Component Object Model) connect Photoshop, it can be used in any DCC software with a python interpreter.

Hello World

import photoshop.api as ps
app = ps.Application()
doc = app.documents.add()
new_doc = doc.artLayers.add()
text_color = ps.SolidColor()
text_color.rgb.red = 0
text_color.rgb.green = 255
text_color.rgb.blue = 0
new_text_layer = new_doc
new_text_layer.kind = ps.LayerKind.TextLayer
new_text_layer.textItem.contents = 'Hello, World!'
new_text_layer.textItem.position = [160, 167]
new_text_layer.textItem.size = 40
new_text_layer.textItem.color = text_color
options = ps.JPEGSaveOptions(quality=5)
# # save to jpg
jpg = 'd:/hello_world.jpg'
doc.saveAs(jpg, options, asCopy=True)
app.doJavaScript(f'alert("save to jpg: {jpg}")')

demo

Photoshop Session

Use it as context.

from photoshop import Session


with Session(action="new_document") as ps:
    doc = ps.active_document
    text_color = ps.SolidColor()
    text_color.rgb.green = 255
    new_text_layer = doc.artLayers.add()
    new_text_layer.kind = ps.LayerKind.TextLayer
    new_text_layer.textItem.contents = 'Hello, World!'
    new_text_layer.textItem.position = [160, 167]
    new_text_layer.textItem.size = 40
    new_text_layer.textItem.color = text_color
    options = ps.JPEGSaveOptions(quality=5)
    jpg = 'd:/hello_world.jpg'
    doc.saveAs(jpg, options, asCopy=True)
    ps.app.doJavaScript(f'alert("save to jpg: {jpg}")')

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Hal
Hal

πŸ’»
voodraizer
voodraizer

πŸ›
brunosly
brunosly

πŸ›
tubi
tubi

πŸ›
wjxiehaixin
wjxiehaixin

πŸ›
η½—ι©¬ι’Ÿ
η½—ι©¬ι’Ÿ

πŸ›
clement
clement

πŸ›
krevlinmen
krevlinmen

πŸ›
Thomas
Thomas

πŸ›
CaptainCsaba
CaptainCsaba

πŸ›
Il Harper
Il Harper

πŸ’»
blunderedbishop
blunderedbishop

πŸ›
MrTeferi
MrTeferi

πŸ’»
Damien Chambe
Damien Chambe

πŸ’»
Ehsan Akbari Tabar
Ehsan Akbari Tabar

πŸ›
Michael Ikemann
Michael Ikemann

πŸ›
Enguerrand DE SMET
Enguerrand DE SMET

πŸ’»
Proton
Proton

πŸ’»

This project follows the all-contributors specification. Contributions of any kind are welcome!

Repobeats analytics

Repobeats analytics

how to get Photoshop program ID

Get-ChildItem "HKLM:\SOFTWARE\Classes" |
  ?{ ($_.PSChildName -match "^[a-z]+\.[a-z]+(\.\d+)?$") -and ($_.GetSubKeyNames() -contains "CLSID") } |
  ?{ $_.PSChildName -match "Photoshop.Application" } | ft PSChildName

get_program_id

How to get a list of COM objects from the registry

Useful links

πŸ› οΈ Development Guide

Welcome to the development guide for the Photoshop Python API project! This section outlines our development practices and standards to ensure code quality and consistency.

πŸ“‹ Quick Start for Contributors

# Clone the repository
git clone https://github.com/loonghao/photoshop-python-api.git
cd photoshop-python-api

# Install dependencies with Poetry
poetry install

# Install pre-commit hooks
pre-commit install

# Run tests
pytest

🎨 Code Style & Quality

We maintain high code quality standards through automated tools and consistent style guidelines:

  • Style Guide: We follow the Google Python Style Guide with project-specific adjustments:

    • Line length: 120 characters max
    • Docstrings: Google style format
    • Quotes: Double quotes preferred
  • Quality Tools:

πŸ”„ Git Workflow

We use a structured workflow to maintain a clean and organized repository:

  • Commit Messages: Follow Conventional Commits format

    <type>(<scope>): <description>
    
    [optional body]
    
    [optional footer(s)]
    

    Common types: feat, fix, docs, style, refactor, test, chore

  • Branching Strategy:

    • Main branch: main - Always stable and deployable
    • Feature branches: feature/<feature-name>
    • Bug fixes: fix/<bug-description>
    • Documentation: docs/<doc-description>

πŸ§ͺ Testing

We value thorough testing to ensure reliability:

  • Framework: We use pytest for all tests
  • Coverage: Aim for high test coverage on new features
  • Run Tests: pytest or poetry run pytest

πŸ“¦ Development Environment

  • Python Versions: We support Python 3.8+ (see pyproject.toml for specifics)
  • Dependency Management: Poetry for consistent environments
  • Virtual Environment: Poetry automatically creates and manages virtual environments

🀝 Contributing Process

  1. Fork & Clone: Fork the repository and clone your fork
  2. Branch: Create a feature branch with a descriptive name
  3. Develop: Make your changes following our code style guidelines
  4. Test: Ensure all tests pass and add new tests for new features
  5. Commit: Use conventional commit format for clear history
  6. Push & PR: Push your branch and create a Pull Request
  7. Review: Address any feedback from code reviews
  8. Merge: Once approved, your PR will be merged

Thank you for contributing to the Photoshop Python API project! πŸŽ‰