As scripting is not really under any kind of control, there are a lot of solutions available. For start, KiCad supports footprint wizard plugins and action plugins.
The action plugins support is available only in nightly releases, while the footprint wizards plugins are available also in 4.0.7 (probably also in earlier versions). The plugins extend the KiCad functionality usually with additional GUI elements. The plugins have to be placed in certain folders. On Windows that is usually
C:\Program Files\KiCad\share\kicad\scripting\plugins. Once the plugin is put in appropriate location it can be run (the KiCad has to be restarted to rescan the folder for plugins).
The footprint wizard plugins are run in the footprint editor by clicking the “new footprint using the footprint wizard” icon in the top menu. The action plugin is run in pcbnew menu “tools/external plugins”
Additionally there is a support for scripting via scripting console, which you can open in pcbnew. Here you can run any python file and the file can be located anywhere on the system.
Also there are quite a few python modules/packages which can be run without any Kicad/pcbnew.
A lot of these solutions are listed in KiCad Third-Party Tools.