The script bit need to be run from Gimp. Gimp isn't designed to be an image processing library, but to be a GUI image editor. So your
Python script would have to explicitly start Gimp, and give it the script to run, and possibly a source directory, see
here(just repalce .BAT/sheel by
Python).
Another solution is to write a Gimp script/plugin, and start it from inside Gimp.
But IMHO if you are in
Python, there are plenty of image libraries that can do this, such as Pillow. You can also use
ImageMagick, either by calling as a command or using its
python bindings. Using Gimp for this is really one of the most complicated ways I can imagine.