Wifi provides a command line wrapper for iwlist and /etc/network/interfaces that makes it easier to connect the WiFi networks from the command line. The wifi command is also implemented as a library that can be used from Python.
# pip install wifi # wifi --help
The documentation for wifi lives at https://wifi.readthedocs.org/en/latest/.