I have some code that looks like this:
from pyparsing import Word, alphas, Optional, ...
# Do stuff ...
# And at the end, save a result to the outside world.
The usual ways to control namespace pollution are
These techniques are all used by the core developers in the standard library. For example, the decimal module:
starts out with private name imports such as import math as _math etc.
Later it does work to setup a threading environment followed by variable deletion using del sys, MockThreading.
In addition, it defines an __all__ variable to make clear what the public API is.
Taken together, these techniques keep the namespace as clean as a whistle.