Forge 1.12.2
Python(Jython) 2.7
Using:
1. open game console
2. type "/ pythoncode", where 'pythoncode' is your code. Example "/ print('Hello, world!')" or "/ import sys"
3. Press "Enter"
PyCraft creates folder "mods/scripts" and file "mods/scripts/pycraft.py", where you can find API. File "pycraft.py" will be rewrited when you rerun minecraft or execute "/pycraft reset" in game console. For your own scripts create file "init.py", which will loaded(executed) by "pycraft.py".
http://minecraft.gamepedia.com/index.php?title=Key_Codes/Keyboard1&action=render
For binding python commands on keys use KeyBinder