Pycairo is set of Python bindings for the cairo graphics library.
Download
The latest stable release is pycairo-1.4.12.
The latest development version may be checked out from CVS using the following command:
cvs -d :pserver:anoncvs@cvs.freedesktop.org:/cvs/cairo co pycairo
Occasionally a development snapshot may also be released. The latest snapshot is pycairo-1.1.6.
Documentation
Currently there is no Python specific cairo API documentation. However there is the cairo C documentation which can be useful. There is also a NOTES file in the tarball release which lists how Pycairo differs from the cairo C API, and there are Pycairo examples in the examples/ directory of the tarball release.
Example
This simple examples draws a blue triangle into a png file.
#!/usr/bin/env python
import cairo
WIDTH, HEIGHT = 400, 400
# Setup Cairo
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
ctx = cairo.Context(surface)
# Set thickness of brush
ctx.set_line_width(15)
# Draw out the triangle using absolute coordinates
ctx.move_to(200, 100)
ctx.line_to(300, 300)
ctx.rel_line_to(-200, 0)
ctx.close_path()
# Apply the ink
ctx.stroke()
# Output a PNG file
surface.write_to_png("triangle.png")
Several other pycairo resources are available.
License
Pycairo is free software and is available to be redistributed and/or modified under the terms of either the GNU Lesser General Public License (LGPL) version 2.1 or the Mozilla Public License (MPL) version 1.1.
Contact
Mailing list: cairo mailing lists
Bugzilla: List open bugs | Report a bug
