I want to create and rasterize vector graphics in Python. I suspect that Pycairo
or cairocffi
(edit: or Qahirah
) are a great choice. (If not, comments are welcome.)
What are the practical differences between the two?
Specifically, the Pycairo
documentation says:
If Pycairo is not what you need, have a look at cairocffi, which is an API compatible package using cffi or Qahirah, which is using ctypes and provides a more "pythonic" API with less focus on matching the cairo C API.
But this raises some questions: In what cases may Pycairo be "not what you need", whereas cairocffi is? In what way are cffi/Qahirah/ctypes better than whatever Pycairo does instead? In what ways is Pycairo not "pythonic"? If cairocffi is better than Pycairo, why is Pycairo more popular, does it have advantages?
Edit: A comma might be missing after "cffi" in the quote above. In that case, it's not about "Pycairo vs. cairocffi", but about "Pycairo vs. cairocffi vs. Qahirah".
Mimicking the C API closely means that functions take simple arguments.
As an example, the move_to
function/method looks like this:
ctx.move_to(x: float, y: float)→ None
If you want to use (x,y) points or vectors in your program,
then at some point you might get annoyed that you need to write,
say, move_to(P[0], P[1])
instead of just move_to(P)
.
In Qahirah you write this:
p = Vector(x, y)
ctx.move_to(p)
or perhaps
ctx.move_to(Vector(x, y))
or even
ctx.move_to((x, y))
You can think of the C API as a base level on top it is possible to build more convenient API.
As always, it is a trade-off. Using a direct style C API might be faster (but not much).
More information can be found in the README for Qahirah:
https://github.com/ldo/qahirah
Then again - if you find a Cairo tutorial using C, it might be easier to use the direct style C API.
Try them both and see what you like.