It seems that termcolor always checks sys.stdout for being a TTY, instead of the file you are actually outputting to.
A consequence of this is that termcolor will not color output to sys.stderr when a program is used in a pipe. This is an unfortunate limitation.
It makes sense that colored always checks sys.stdout, since it has no way of knowing what the output file will be. However, I would like to request there to be some way of explicitly specifying the intended output file, perhaps via an optional output_file argument.
For cprint, this is arguably a bug. I believe it could be fixed by looking for the file argument in kwargs and then checking that instead of sys.stdout.