Add Py3 changes to production python files.
Changes
This MR adds all updated Py3 files that are used in production.
This repeats all changes from !226 (closed) for these files.
Purpose
I intend to split !226 (closed)'s changes into a number of MRs, which won't be functional code versions themselves, but once complete will encompass the full set of changes to upgrade to py3.
This should provide useful code diffs for reviewers.