Skip to main content

krita4python

Pure-Python reader and writer for Krita's native .kra files. No Krita install required, no C extension required, and it runs on every Python that Pillow supports (3.9 – 3.13+).

kritapy/kra-py on PyPI is write-only and breaks on Python 3.12+; krita4python is a clean-room reimplementation against the documented format so it stays working.

Install

pip install krita4python

Optional speedups (NumPy for the planar/interleaved conversion, python-lzf for the C LZF codec):

pip install "krita4python[speed]"

Everything still works without them, it's just slower on big layers.

Read a .kra

from krita4python import read_kra

doc = read_kra("character.kra")
print(doc.width, doc.height)
for layer in doc.iter_paint_layers():
    print(layer.name, layer.x, layer.y, layer.opacity, layer.visible)
    if layer.image is not None:
        layer.image.save(f"{layer.name}.png")

doc.layers is a tree of KraGroup/KraLayer nodes in back-to-front order. layer.image is a Pillow RGBA image sized to the layer's tight bounding box; layer.x/y is its canvas offset.

Write a .kra

from PIL import Image
from krita4python import write_kra, KraDocument, KraLayer

doc = KraDocument(
    width=1024, height=1024,
    layers=[
        KraLayer(name="bg", image=Image.open("bg.png")),
        KraLayer(name="char", image=Image.open("char.png"), x=128, y=64),
    ],
)
write_kra("out.kra", doc)

The resulting file opens in Krita 5.x and round-trips back through read_kra.

CLI

krita4python extract character.kra -o ./layers/
krita4python pack ./layers/ -o repacked.kra

What's supported

  • RGBA / 8-bit paint layers (the format used by 99%+ of .kra files).
  • Group layers, nesting, visibility, opacity, composite-op, layer offsets.
  • mergedimage.png and preview.png (auto-generated on write).
  • Tile-level LZF compression with the documented planar BGRA layout.

What's NOT supported (yet)

  • Non-8-bit color depths (16f / 32f).
  • Non-RGBA colorspaces (CMYK, grayscale).
  • Filter, vector, transform-mask, file-reference, clone layers (we surface their metadata but not pixels).
  • Per-layer ICC profiles.

PRs welcome.

Why does this exist

OpenLive2D needed real .kra reading on Python 3.13 (where kritapy raises a dataclass error on import). Rather than depend on Krita running headlessly, krita4python reimplements the format. License is GPL-3.0.

Metadata

Release files for krita4python 0.1.2.post20260512

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for krita4python 0.1.2.post20260512
File Size Uploaded Provenance Actions
krita4python-0.1.2.post20260512.tar.gz 30.3 kB Without provenance Details for krita4python-0.1.2.post20260512.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for krita4python 0.1.2.post20260512
File Interpreter ABI Platform Actions
krita4python-0.1.2.post20260512-py3-none-any.whl Python 3 none any Details for krita4python-0.1.2.post20260512-py3-none-any.whl

Total release size: 61.0 kB

Release files / krita4python-0.1.2.post20260512.tar.gz

Download URL krita4python-0.1.2.post20260512.tar.gz
Size 30.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ecc71044f919b0efc2e45d4cb444f4601f6246751d844a9e2e53d9d55122ae04
BLAKE2b-256 checksum
How to use checksums
20c6a0563070b2b5c4fbdedfa8010c601e1b554bce9e812651c34ccab64e7ef8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Release files / krita4python-0.1.2.post20260512-py3-none-any.whl

Download URL krita4python-0.1.2.post20260512-py3-none-any.whl
Size 30.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e69d07072dbc9a189d5ee20205c19bdb028e348417a0a74dc530af7bb8371ab5
BLAKE2b-256 checksum
How to use checksums
6c5219926c3abc0c9f3f5cbb38c87d13f656fa90c75e69e4b1a0ce33071b955b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Security for krita4python 0.1.2.post20260512

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page