mode = os.fstat(0).st_mode
if stat.S_ISFIFO(mode):
    print('stdin is piped')
elif stat.S_ISREG(mode):
    pass
How do I determine if sys.stdin is redirected from a file vs. piped from another process?