There are numerous python API libraries we can use to access GPIO from py scripts.
Python libraries
GPIO Zero Built into raspberry PI OS since last couple years for Python. Written by Pi founder or something. Just use this
RPi.GPIO Needs install best for Python since 2012
Wiring Pi is for C.
GPIO Zero Lib is NOT preinstalled on retropie.
https://gpiozero.readthedocs.io/en/stable/installing.html
So I guess just always install it on fresh retropie image.
sudo apt update press Y
sudo apt install python3-gpiozero