You can use Midi Sheet Music
free and open source
plays MIDI music files while highlighting the piano notes and sheet music notes
supports multiple channels
Works on Windows, Mac OS X, and Ubuntu Linux.
Export the sheets to PDF
There is a music notation program called Lilypond which includes a command line interface and a command line midi2ly converter that will read in a midi file and output a lilypond file.
Should work on linux Yes and OS/X, Windows
Should be able to run in terminal Yes or GUI for the main program
Should be able to save the music sheet in a image format: jpeg or ...
I would suggest taking a look at Denemo which seems to fit a lot of your requirements:
Music input from teh PC Keyboard, MIDI Controller or acoustically
Produces sheet music in various notations vial LilyPond to produce beautifully typeset sheet music.
Your music can produce prints, images and music files as well routing your music in real time to other ...
LilyPond is a sheet music typesetting or "engraving" tool that supports producing sheet music in both formal score & guitar tablature (it even supports Gregorian chant notation).
There are several python libraries that can interact with Lilypond listed on pypi and Lilypond has its own API or can be invoked with text input.
If you prefer the GUI part in your question, I would recommend MuseScore. It is Open Source and has a Plugin System, so you may extend it to your needs. MuseScore is based on Qt.
However, if you are looking for an even more programmable approach, you should check LilyPond. This is kind of LaTeX for music notation.
I would suggest taking a look at LilyPond it is one of the best music typesetting packages available:
Free, Gratis & Open Source
Cross Platform Windows, Linux & OS-X
Includes multiple types of music notation from Gregorian Chants to full orchestration, including cording.
You can even find a recipe for creating a booklet at https://github.com/...