LilyLib is a python library that provides a mid-level language for writing sheet music. It lets you write music in terms of scales, arpeggios, key changes, motifs, transpositions, and so on. It can be compiled into Lilypond which can then be compiled into a pdf. You can get the code, including documentation, here. For some typeset pieces (romantic era piano pieces) see here.