Software or library for creating images of ball and stick models?
For general open source solutions:


Avogadro - Molecular editor GUI. Has a Python API.
Jmol - Chemical structure viewer. Fully scriptable using a custom scripting language. It also has a JavaScript-only version named 'JSmol', allowing models to be displayed in web browsers.
ghemical - Has a GUI for editing molecules, but no API.


For a $\LaTeX$ solution, see this question on the $\TeX$ Stack Exchange site: Help creating solid cylinders along a path in Tikz for crystal lattice diagram

Other solutions:


If you have access to Mathematica (e.g. on a Raspberry Pi running Raspbian [which comes with a free copy of Mathematica]), you can use Mathematica's ChemicalData built-in symbol to create ball and stick models.