pip install pylibretro
You can install the dependencies for the examples in examples
or the snippet below by running pip install pylibretro[examples]
You can create the GIF shown above by using the example file in this repository. However, here's a condensed, minimal usage example:
from pylibretro import Core, buttons
import platform
from PIL import Image
lastframe = None
def on_frame(frame):
global lastframe
lastframe = frame
# Load the core
if platform.system() == "Linux":
core = Core("./2048_libretro.so")
elif platform.system() == "Windows":
core = Core("2048_libretro.dll")
core.on_video_refresh = on_frame
core.init()
core.load_game(None)
# Start a 2048 game (by pressing the START button for one frame)
core.joystick[buttons.START] = True
core.run()
core.joystick[buttons.START] = False
# Run core for 10 frames
for i in range(10):
core.run()
# Show the last screen output
lastframe = Image.fromarray(lastframe)
lastframe.show()
pylibretro is licensed under GPLv3 or later.
Credits to the RetroArch team for the libretro API and also the 2048 core included within this repository as an example. Their corresponding licenses are also included in the license file.