Nightly has Action Script, but in 4.0.x you'll need to open Scripting Console and type import pythonfilename
Here are some basics:
(The folder is the same, but only nightly has the menu item).
Place the layerviewset.py and layerviewset_gui.py files in C:\Program Files\KiCad\share\kicad\scripting\plugins Or the equivalent in MacOS or Linux (there may be a user-level directory for such files, but I am not aware of it at the moment.)
Within KiCad pcbnew, select the Tools > External Plugins > Refresh Plugins