Skip to main content

PyPI Github Releases Downloads PyPI Downloads License Docs Versions

Game-State

A lightweight, framework-agnostic library for managing application and game states with lifecycle hooks, overlays, and async support.

Table of Contents

Requirements

This library supports python versions 3.8 - 3.14.

Installation

Create and activate a virtual environment in your workspace (optional) and run the following command-

pip install game_state

Note: This package does not have any dependancy on pygame, hence you will need to install them separately on your own. This gives you the freedom to work with pygame, pygame-ce or any other library.

Getting Started

This is an example of creating two screens. One displaying green colour and the other blue with a player.

import pygame
from game_state import State, StateManager
from game_state.utils import MISSING


GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
speed = 200
pygame.init()
pygame.display.init()
pygame.display.set_caption("Game State Example")


class MyBaseState(State["MyBaseState"]):
    window: pygame.Surface = MISSING
    # Attributes we want all our states to share.

    def process_event(self, event: pygame.event.Event) -> None:
        pass

    def process_update(self, dt: float) -> None:
        pass


class MainMenuState(MyBaseState, state_name="MainMenu"):
    def process_event(self, event: pygame.event.Event) -> None:
        if event.type == pygame.QUIT:
            self.manager.is_running = False

        if event.type == pygame.KEYDOWN and event.key == pygame.K_w:
            self.manager.change_state("Game")

    def process_update(self, dt: float) -> None:
        self.window.fill(GREEN)
        pygame.display.update()


class GameState(MyBaseState, state_name="Game"):
    def __init__(self) -> None:
        self.player_x: float = 250.0

    def process_event(self, event: pygame.event.Event) -> None:
        if event.type == pygame.QUIT:
            self.manager.is_running = False

        if event.type == pygame.KEYDOWN and event.key == pygame.K_w:
            self.manager.change_state("MainMenu")

    def process_update(self, dt: float) -> None:
        self.window.fill(BLUE)

        pressed = pygame.key.get_pressed()
        if pressed[pygame.K_a]:
            self.player_x -= speed * dt

        if pressed[pygame.K_d]:
            self.player_x += speed * dt

        pygame.draw.rect(
            self.window,
            "red",
            (self.player_x, 100, 50, 50),
        )
        pygame.display.update()


def main() -> None:
    window = pygame.display.set_mode((500, 600))

    state_manager = StateManager(bound_state_type=MyBaseState, window=window)
    state_manager.load_states(MainMenuState, GameState)
    state_manager.change_state("MainMenu")

    clock = pygame.time.Clock()

    while state_manager.is_running:
        dt = clock.tick(60) / 1000

        for event in pygame.event.get():
            state_manager.current_state.process_event(event)

        state_manager.current_state.process_update(dt)


if __name__ == "__main__":
    main()

You can have a look at the game state guide for a more detailed explaination.

Metadata

Release files for game-state 2.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for game-state 2.5.1
File Size Uploaded Provenance Actions
game_state-2.5.1.tar.gz 25.0 kB With provenance Details for game_state-2.5.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for game-state 2.5.1
File Interpreter ABI Platform Actions
game_state-2.5.1-py3-none-any.whl Python 3 none any Details for game_state-2.5.1-py3-none-any.whl

Total release size: 50.5 kB

Release files / game_state-2.5.1.tar.gz

Download URL game_state-2.5.1.tar.gz
Size 25.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d0faab915a6a2c0ee341e603d75f09d12a84ce602965060667ae4b67a2cc0790
BLAKE2b-256 checksum
How to use checksums
a6149f3b61f1f714479a57c8be1ad08e547069dc50f6240c3d41ed95bcda2fd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

Release files / game_state-2.5.1-py3-none-any.whl

Download URL game_state-2.5.1-py3-none-any.whl
Size 25.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
24f3c7486fb86a33c2c4371f5fa24f7633f3e1206975bb8f6ecbb12b9834446c
BLAKE2b-256 checksum
How to use checksums
df25fb7056e24573293616ea7ed928724ed642d31ec832af6abcd9b79debfdda
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

Security for game-state 2.5.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for game_state-2.5.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page