Create a proper package and split into modules
This module is quite lengthy. Some PEP 8 love and additional docstrings will only increase the line count. Splitting up the module into a package with submodules would make code review and contribution easier.
A quick review shows some candidates for separate modules: constants exceptions tables types utilities