Skip to main content

Game Boy emulator written in Python

Project description

If you have any questions, or just want to chat, join us on Discord.

Discord

Train RL agents to play Pokemon Red Rewind any game
Play the classics
Create your own AI
Beat world records with AI

Getting Started

The instructions are simple:

$ pip install pyboy

For details, see installation instructions.

Now you're ready! Either use PyBoy directly from the terminal

$ pyboy game_rom.gb

Or use it in your Python scripts:

from pyboy import PyBoy
pyboy = PyBoy('game_rom.gb')
while pyboy.tick():
    pass
pyboy.stop()

The API

If you are looking to make a bot or AI, then these resources are a good place to start:

When the emulator is running, you can easily access PyBoy's API:

pyboy.set_emulation_speed(0) # No speed limit
pyboy.button('down')
pyboy.button('a')
pyboy.tick() # Process at least one frame to let the game register the input
value_of_interest = pyboy.memory[0xC345]

pil_image = pyboy.screen.image
pil_image.save('screenshot.png')

The Wiki shows how to interface with PyBoy from your own project.

Performance

Performance is a priority for PyBoy, to make your AI training and scripts as fast as possible.

The easiest way to improve your performance, is to skip rendering of unnecessary frames. If you know your character takes X frames to move, or the game doesn't take input every frame, you can skip those to potentially triple your performance. All game logic etc. will still process.

Here is a simple comparison of rendering every frame, rendering every 15th frame, and not rendering any frames (higher is better). See pyboy.tick for how it works. Your performance will depend on the game.

Full rendering Frame-skip 15 No rendering
x124 realtime x344 realtime x395 realtime
for _ in range(target):
    pyboy.tick()
for _ in range(target//15):
    pyboy.tick(15, True)
pyboy.tick(target)

The Game Boy was originally running at 60 frames per second, so a speed-up of 100x realtime is 6,000 frames per second. And trivially from the table above, simulating 395 hours of gameplay can be done in 1 hour with no rendering.

It's also recommended to be running multiple instances of PyBoy in parallel. On an 8-core machine, you could potentially do 3160 hours of gameplay in 1 hour.

Contributing

Any contribution is appreciated. The currently known problems are tracked in the Issues tab. Feel free to take a swing at any one of them. If you have something original in mind, come and discuss it on on Discord.

Discord

For the more major features, there are the following that you can give a try. They are also described in more detail in the project list in the Wiki:

  • Hacking games
  • Link Cable
  • Debugger (VSCode, GDB, terminal or otherwise)
  • AI - use the api or game wrappers to train a neural network
  • Game Wrappers - make wrappers for popular games

If you want to implement something which is not on the list, feel free to do so anyway. If you want to merge it into our repo, then just send a pull request and we will have a look at it.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyboy-2.2.0.tar.gz (158.7 kB view hashes)

Uploaded Source

Built Distributions

pyboy-2.2.0-cp312-cp312-win_amd64.whl (3.8 MB view hashes)

Uploaded CPython 3.12 Windows x86-64

pyboy-2.2.0-cp312-cp312-musllinux_1_2_x86_64.whl (5.0 MB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

pyboy-2.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (4.8 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.28+ x86-64

pyboy-2.2.0-cp312-cp312-macosx_10_9_universal2.whl (8.1 MB view hashes)

Uploaded CPython 3.12 macOS 10.9+ universal2 (ARM64, x86-64)

pyboy-2.2.0-cp311-cp311-win_amd64.whl (3.8 MB view hashes)

Uploaded CPython 3.11 Windows x86-64

pyboy-2.2.0-cp311-cp311-musllinux_1_2_x86_64.whl (5.1 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.2+ x86-64

pyboy-2.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (5.0 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.28+ x86-64

pyboy-2.2.0-cp311-cp311-macosx_10_9_universal2.whl (8.0 MB view hashes)

Uploaded CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)

pyboy-2.2.0-cp310-cp310-win_amd64.whl (3.8 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

pyboy-2.2.0-cp310-cp310-musllinux_1_2_x86_64.whl (5.2 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.2+ x86-64

pyboy-2.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (5.0 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.28+ x86-64

pyboy-2.2.0-cp310-cp310-macosx_10_9_universal2.whl (8.1 MB view hashes)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

pyboy-2.2.0-cp39-cp39-win_amd64.whl (3.9 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

pyboy-2.2.0-cp39-cp39-musllinux_1_2_x86_64.whl (5.2 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.2+ x86-64

pyboy-2.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (5.0 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.28+ x86-64

pyboy-2.2.0-cp39-cp39-macosx_10_9_universal2.whl (8.1 MB view hashes)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)

pyboy-2.2.0-cp38-cp38-win_amd64.whl (3.9 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

pyboy-2.2.0-cp38-cp38-musllinux_1_2_x86_64.whl (5.2 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.2+ x86-64

pyboy-2.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (5.1 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.28+ x86-64

pyboy-2.2.0-cp38-cp38-macosx_11_0_universal2.whl (8.3 MB view hashes)

Uploaded CPython 3.8 macOS 11.0+ universal2 (ARM64, x86-64)

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page