It’s pretty easy. You have three basic streams:
1. Stdin - just iterate through sys.stdin
2. Stdout - regular printing will go there
3. Stderr - print errors here eg with print(…, file=sys.stderr)
And then beyond that as long as your script gets invoked by the interpreter (Ie #!/usr/bin/env python) everything will “just work”.