pycairo

Python interface for cairo

LGPL-2.1-only OR MPL-1.1 44 个版本 Python >=3.10
安装
pip install pycairo
poetry add pycairo
pipenv install pycairo
conda install pycairo
描述

.. image:: https://raw.githubusercontent.com/pygobject/pycairo/main/docs/images/pycairo.svg :align: center :width: 370px

|

Pycairo is a Python module providing bindings for the cairo graphics library <https://cairographics.org/>. It depends on cairo >= 1.15.10 and works with Python 3.10+ and PyPy3. Pycairo, including this documentation, is licensed under the LGPL-2.1-only OR MPL-1.1 <https://spdx.dev/ids>.

The Pycairo bindings are designed to match the cairo C API as closely as possible, and to deviate only in cases which are clearly better implemented in a more ‘Pythonic’ way.

.. code:: shell

pip install pycairo

Installing Pycairo requires cairo including its headers. For more info see "Getting Started <https://pycairo.readthedocs.io/en/latest/getting_started.html>__".


.. code:: python

import cairo

with cairo.SVGSurface("example.svg", 200, 200) as surface:
    context = cairo.Context(surface)
    x, y, x1, y1 = 0.1, 0.5, 0.4, 0.9
    x2, y2, x3, y3 = 0.6, 0.1, 0.9, 0.5
    context.scale(200, 200)
    context.set_line_width(0.04)
    context.move_to(x, y)
    context.curve_to(x1, y1, x2, y2, x3, y3)
    context.stroke()
    context.set_source_rgba(1, 0.2, 0.2, 0.6)
    context.set_line_width(0.02)
    context.move_to(x, y)
    context.line_to(x1, y1)
    context.move_to(x2, y2)
    context.line_to(x3, y3)
    context.stroke()

.. image:: https://raw.githubusercontent.com/pygobject/pycairo/main/docs/images/example.svg :width: 320px :align: center


Features of the Pycairo bindings:

  • Provides an object oriented interface to cairo.
  • Queries the error status of objects and translates them to exceptions.
  • Provides a C API that can be used by other Python extensions.
  • Fully typed and documented API.

For more information visit https://pycairo.readthedocs.io

版本列表
1.29.0 2025-11-11
1.28.0 2025-04-14
1.27.0 2024-09-06
1.26.1 2024-06-21
1.26.0 2024-02-11
1.25.1 2023-10-21
1.25.0 2023-09-26
1.24.0 2023-06-19
1.23.0 2022-11-28
1.22.0 2022-11-19
1.21.0 2022-03-07
1.20.1 2021-06-03
1.20.0 2020-10-05
1.19.1 2020-02-16
1.19.0 2020-01-23
1.18.2 2019-10-24
1.18.1 2019-04-19
1.18.0 2018-11-04
1.17.1 2018-07-07
1.17.0 2018-04-15
1.16.3 2018-02-27
1.16.2 2018-02-10
1.16.1 2018-02-06
1.16.0 2018-02-05
1.15.6 2018-01-30
1.15.5 2018-01-29
1.15.4 2017-12-07
1.15.3 2017-12-07
1.15.2 2017-12-07
1.15.1 2017-12-07
1.15.0 2017-12-07
1.14.1 2017-12-07
1.14.0 2017-12-07
1.13.4 2017-12-07
1.13.3 2017-12-07
1.13.2 2017-12-07
1.13.1 2017-12-07
1.13.0 2017-12-07
1.12.0 2017-12-07
1.11.1 2017-12-07
1.11.0 2017-12-07