Skip to main content

Cython bindings for the ThorVG vector graphics library

Project description

thorvg-cython

Cython bindings for the ThorVG vector graphics library.

Overview

This package provides direct C-level bindings to ThorVG via Cython — no ctypes overhead. It mirrors the thorvg-python API surface while delivering native-extension performance.

Platform Support

Platform Linking Strategy
iOS (sys.platform == "ios") Links against thorvg.xcframework static slice
macOS (sys.platform == "darwin") Links against libthorvg.a or libthorvg-1.dylib
Linux Links against libthorvg.so
Windows Links against thorvg.lib / thorvg-1.dll
Android Links against libthorvg.so

Building

Prerequisites

  • Python ≥ 3.9
  • Cython ≥ 3.0
  • ThorVG built with C API bindings (-Dbindings=capi)

Quick Build (macOS)

# 1. Build ThorVG
cd /path/to/thorvg
export SDKROOT=$(xcrun --show-sdk-path)
meson setup builddir --buildtype=release --default-library=static -Dbindings=capi -Dloaders=svg,lottie,ttf
ninja -C builddir

# 2. Build the wheel
cd thorvg-cython
THORVG_ROOT=.. THORVG_LIB_DIR=../builddir/src pip install -e .

Environment Variables

Variable Description Default
THORVG_ROOT Path to thorvg source root Parent of this package
THORVG_INCLUDE Path to thorvg.h $THORVG_ROOT/inc
THORVG_LIB_DIR Path to built libraries $THORVG_ROOT/output
THORVG_XCFRAMEWORK Path to .xcframework $THORVG_ROOT/output/thorvg.xcframework
THORVG_CAPI_INCLUDE Path to thorvg_capi.h $THORVG_ROOT/src/bindings/capi

cibuildwheel

pip install cibuildwheel
cibuildwheel --platform macos

Usage

import thorvg_cython as tvg

with tvg.Engine(threads=2) as engine:
    canvas = tvg.SwCanvas(800, 600)
    shape = tvg.Shape()
    shape.append_rect(0, 0, 100, 100, rx=10, ry=10)
    shape.set_fill_color(255, 0, 0)
    canvas.add(shape)
    canvas.draw()
    canvas.sync()

Zero-Copy Buffer Protocol (PEP 3118)

SwCanvas implements the Python buffer protocol directly — no intermediate copies needed when passing pixel data to other frameworks.

Snapshot as bytes:

import thorvg_cython as tvg

with tvg.Engine(threads=2):
    canvas = tvg.SwCanvas(800, 600)

    # Draw a red rounded rectangle
    shape = tvg.Shape()
    shape.append_rect(50, 50, 200, 150, rx=20, ry=20)
    shape.set_fill_color(255, 0, 0)
    canvas.add(shape)

    # Load and render an SVG
    pic = tvg.Picture()
    pic.load("icon.svg")
    pic.set_size(100, 100)
    canvas.add(pic)

    canvas.draw()
    canvas.sync()

    raw = bytes(canvas)  # flat RGBA, 800×600×4 = 1_920_000 bytes

Kivy texture (zero-copy blit):

from kivy.graphics.texture import Texture
import thorvg_cython as tvg

with tvg.Engine():
    texture = Texture.create(size=(800, 600), colorfmt='rgba')
    canvas = tvg.SwCanvas(800, 600)

    # Load a Lottie animation
    pic = tvg.Picture()
    pic.load("animation.json")
    pic.set_size(800, 600)
    canvas.add(pic)

    # Initial render
    canvas.draw()
    canvas.sync()
    texture.blit_buffer(canvas, colorfmt='rgba', bufferfmt='ubyte')

    # Move the animation and re-render — same canvas, same texture
    pic.translate(100, 50)
    pic.set_opacity(180)
    canvas.update()
    canvas.draw()
    canvas.sync()
    texture.blit_buffer(canvas, colorfmt='rgba', bufferfmt='ubyte')

NumPy array (zero-copy view):

import numpy as np
import thorvg_cython as tvg

with tvg.Engine():
    canvas = tvg.SwCanvas(400, 300)

    shape = tvg.Shape()
    shape.append_circle(200, 150, 100, 100)
    shape.set_fill_color(0, 120, 255)
    canvas.add(shape)
    canvas.draw()
    canvas.sync()

    # Live view into the canvas pixel buffer — no copy
    arr = np.frombuffer(canvas, dtype=np.uint8).reshape(300, 400, 4)
    arr[:, :, 3] = 128  # set alpha to 50% — modifies canvas directly

memoryview (stdlib, zero-copy):

import thorvg_cython as tvg

with tvg.Engine():
    canvas = tvg.SwCanvas(256, 256)

    shape = tvg.Shape()
    shape.append_rect(0, 0, 256, 256)
    shape.set_fill_color(0, 0, 0)
    canvas.add(shape)
    canvas.draw()
    canvas.sync()

    mv = memoryview(canvas)
    print(len(mv))  # 262_144
    mv[0:4]          # first pixel RGBA bytes

License

MIT — same as ThorVG.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

thorvg_cython-0.0.1.tar.gz (235.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

thorvg_cython-0.0.1-cp313-cp313-win_amd64.whl (565.7 kB view details)

Uploaded CPython 3.13Windows x86-64

thorvg_cython-0.0.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

thorvg_cython-0.0.1-cp313-cp313-macosx_11_0_arm64.whl (572.4 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

thorvg_cython-0.0.1-cp313-cp313-ios_13_0_x86_64_iphonesimulator.whl (2.4 MB view details)

Uploaded CPython 3.13iOS 13.0+ x86-64 Simulator

thorvg_cython-0.0.1-cp313-cp313-ios_13_0_arm64_iphonesimulator.whl (2.4 MB view details)

Uploaded CPython 3.13iOS 13.0+ ARM64 Simulator

thorvg_cython-0.0.1-cp313-cp313-ios_13_0_arm64_iphoneos.whl (2.4 MB view details)

Uploaded CPython 3.13iOS 13.0+ ARM64 Device

thorvg_cython-0.0.1-cp313-cp313-android_24_x86_64.whl (1.1 MB view details)

Uploaded Android API level 24+ x86-64CPython 3.13

File details

Details for the file thorvg_cython-0.0.1.tar.gz.

File metadata

  • Download URL: thorvg_cython-0.0.1.tar.gz
  • Upload date:
  • Size: 235.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for thorvg_cython-0.0.1.tar.gz
Algorithm Hash digest
SHA256 4f1ad19189b569cdd89ad3aa801ee4147b7d554cdff71c09440b88c1d6986143
MD5 2f7d2a40291457579dbed1c048f9415f
BLAKE2b-256 058508af66a6e27e1f1140fb766fb59cb68ac3cebd728b7308e18263554e7608

See more details on using hashes here.

Provenance

The following attestation bundles were made for thorvg_cython-0.0.1.tar.gz:

Publisher: pypi-publish.yml on Py-Swift/thorvg-cython

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file thorvg_cython-0.0.1-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for thorvg_cython-0.0.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 482981425c82c4731b13900a13aba580dcf4147417c2f2753d5a2cf5a8e059b5
MD5 22bf5495c8d2a4839dc593801d7bfed6
BLAKE2b-256 eb8effa27abaa458c8e587d469e783dbe78ae3c34080b2637ef23b48ca13ec38

See more details on using hashes here.

Provenance

The following attestation bundles were made for thorvg_cython-0.0.1-cp313-cp313-win_amd64.whl:

Publisher: pypi-publish.yml on Py-Swift/thorvg-cython

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file thorvg_cython-0.0.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for thorvg_cython-0.0.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 85785abac12abcd7f3c27aba761921ba3e24622a199a8d004947ad5d1465a90c
MD5 d8b15284f0b400c48fdfea7ebed481dc
BLAKE2b-256 753cc8f112aa4197a95f8faf5d25cd2831d89cbdc36abe755a81d79c60aceec0

See more details on using hashes here.

Provenance

The following attestation bundles were made for thorvg_cython-0.0.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: pypi-publish.yml on Py-Swift/thorvg-cython

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file thorvg_cython-0.0.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for thorvg_cython-0.0.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 87d441a016e3de77986904f5cfcf9880ab8e61ce998eb400e9e88e44bf52af2b
MD5 857e1e6f06351ff047b541431018773c
BLAKE2b-256 1ffa69e3c745cb385fe9e611504eb055c5abbca2a813229b8dbb1ccaa311c63e

See more details on using hashes here.

Provenance

The following attestation bundles were made for thorvg_cython-0.0.1-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: pypi-publish.yml on Py-Swift/thorvg-cython

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file thorvg_cython-0.0.1-cp313-cp313-ios_13_0_x86_64_iphonesimulator.whl.

File metadata

File hashes

Hashes for thorvg_cython-0.0.1-cp313-cp313-ios_13_0_x86_64_iphonesimulator.whl
Algorithm Hash digest
SHA256 0983951324072565d3999967dce5ef924ffc35105598fb8559ec23c14694eafb
MD5 70c13dc6abfcb00401c08aa880ef3242
BLAKE2b-256 115397ac00280e7b603dee59613cac8ea69032b81347ffd94035bd7a89837fbb

See more details on using hashes here.

Provenance

The following attestation bundles were made for thorvg_cython-0.0.1-cp313-cp313-ios_13_0_x86_64_iphonesimulator.whl:

Publisher: pypi-publish.yml on Py-Swift/thorvg-cython

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file thorvg_cython-0.0.1-cp313-cp313-ios_13_0_arm64_iphonesimulator.whl.

File metadata

File hashes

Hashes for thorvg_cython-0.0.1-cp313-cp313-ios_13_0_arm64_iphonesimulator.whl
Algorithm Hash digest
SHA256 f1083c0d3ea1af2cbcec9654219f07c6c0fb8c8f1824d763b1305900055238de
MD5 63407a8ffaf95c556f8b1c90cf90b36f
BLAKE2b-256 b0d16d1432554e17a96d3220793208adae443d00161d1e3a70075ec71ffb52d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for thorvg_cython-0.0.1-cp313-cp313-ios_13_0_arm64_iphonesimulator.whl:

Publisher: pypi-publish.yml on Py-Swift/thorvg-cython

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file thorvg_cython-0.0.1-cp313-cp313-ios_13_0_arm64_iphoneos.whl.

File metadata

File hashes

Hashes for thorvg_cython-0.0.1-cp313-cp313-ios_13_0_arm64_iphoneos.whl
Algorithm Hash digest
SHA256 a542fee409b840beec45e6e7bc617f29a9c3d9e58c90b72c398d4705ad8e0926
MD5 2939938790de6ad08c415d80c29ff3f0
BLAKE2b-256 32e30cc0df55c8fe6e88c9fb1498e185f9d97985dc33127248db820bd9bac89c

See more details on using hashes here.

Provenance

The following attestation bundles were made for thorvg_cython-0.0.1-cp313-cp313-ios_13_0_arm64_iphoneos.whl:

Publisher: pypi-publish.yml on Py-Swift/thorvg-cython

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file thorvg_cython-0.0.1-cp313-cp313-android_24_x86_64.whl.

File metadata

File hashes

Hashes for thorvg_cython-0.0.1-cp313-cp313-android_24_x86_64.whl
Algorithm Hash digest
SHA256 aaa69cab4a96a7f07a11a96f826df4bc2a584da07d71d9f1890ef8ad3fb9532a
MD5 0272ad7fd73b157aa6afde470f3004b2
BLAKE2b-256 0e24d22a806c0aecd7c5db91a2bf122e9de869de531e076bc2b6b2e8981e8373

See more details on using hashes here.

Provenance

The following attestation bundles were made for thorvg_cython-0.0.1-cp313-cp313-android_24_x86_64.whl:

Publisher: pypi-publish.yml on Py-Swift/thorvg-cython

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page