Skip to main content

Simple Snake Game 🐍

A minimalist snake game written in Python using asyncio. Customize speed, grid size, controls, and even add a poison mode for extra challenge!


Author


Installation

Install the game easily using pip:

From PyPI:

pip install python-snake-game

Or directly from GitHub:

pip install git+https://github.com/ramim-kobir/python-snake-game@v1.0.11

Usage

You can import and run the game from Python code:

import python_snake_game as snake_game

snake_game.play()

Parameters of play function

Parameter Type Default Description
speed int 10 Controls the game speed (higher = faster; range 1–20).
snake_food_emoji str "🍎" Emoji to represent the food on the grid.
grid_size tuple (int,int) (15,12) Size of the game grid as (width, height).
background_emoji str "🟫" Emoji or character to represent the grid blocks.
invisible_wall bool False Snake wraps around edges instead of dying.
poison_mode bool False Adds poisonous food. Snake dies if eaten.

Key Customization Functions

The game allows full key customization via three built-in functions:

  1. automatic_configure_custom_key() Interactively prompts the user at runtime to configure custom keys for movement and pause.

  2. manual_configure_custom_key() Allows the user to edit a configuration file to set preferred keys and save them for future sessions.

  3. reset_key_configuration() Restores default key bindings, undoing any previous customizations.

Example Usage

import python_snake_game as snake_game

# Automatic interactive key configuration
snake_game.automatic_configure_custom_key()

# Manual configuration via config file
snake_game.manual_configure_custom_key()

# Reset keys to default
snake_game.reset_key_configuration()

# Start the game after customizing keys
snake_game.play(speed=10, grid_size=(20, 15), poison_mode=False)

🚀 Command Line Interface – python -m python_snake_game

Run the snake game directly from the command line:

python -m python_snake_game [options]

📥 Available CLI Arguments

Argument Type Default Description
--speed int (1–20) 10 Controls game speed. Higher = faster.
--grid_size string (W,H) 15,12 Grid size as width,height. Must be two positive integers.
--invisible_wall bool False Snake wraps around screen edges instead of dying.
--poison_mode bool False Adds poisonous food. Snake dies if eaten.
--customize_key bool False Enable interactive or file-based key customization before playing.

🧪 Examples

# Run with default settings
python -m python_snake_game

# Custom speed and grid size
python -m python_snake_game --speed 5 --grid_size 20,15

# Enable invisible walls (screen wrapping)
python -m python_snake_game --invisible_wall

# Enable poison mode
python -m python_snake_game --poison_mode

# Customize keys interactively before start game
python -m python_snake_game --customize_key

# All options together
python -m python_snake_game --speed 8 --grid_size 30,20 --invisible_wall --poison_mode --customize_key

Controls

  • Arrow keys (default) to move the snake:

    • Up: w
    • Down: s
    • Left: a
    • Right: d
  • Space bar to pause/resume the game.

  • Custom keys can be configured via CLI or the three customization functions.


How to Play

  • The snake moves continuously on the grid.
  • Eat the food (🍎) to grow longer and increase your score.
  • Avoid hitting walls or your own body unless invisible_wall=True.
  • In poison mode, some food can kill the snake instantly.
  • Current score is displayed above the grid.

🆕 What's New in v1.0.10

  • Custom Key Configuration

    • Automatic – interactively configure keys via automatic_configure_custom_key().
    • Manual – configure keys by editing a configuration file via manual_configure_custom_key().
    • Reset – restore default key bindings using reset_key_configuration().
  • New CLI Argument: --customize_key to trigger key customization before playing.


Notes

  • Uses ANSI escape codes for terminal control (screen clear, colors).
  • Works best on terminals supporting Unicode and ANSI colors.

License

This project is open source. Feel free to contribute or modify!


Metadata

Release files for python-snake-game 1.0.11

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

Source distribution (sdist)

Source distribution for python-snake-game 1.0.11
File Size Uploaded Provenance Actions
python_snake_game-1.0.11.tar.gz 11.3 kB Without provenance Details for python_snake_game-1.0.11.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for python-snake-game 1.0.11
File Interpreter ABI Platform Actions
python_snake_game-1.0.11-py3-none-any.whl Python 3 none any Details for python_snake_game-1.0.11-py3-none-any.whl

Total release size: 22.0 kB

Release files / python_snake_game-1.0.11.tar.gz

Download URL python_snake_game-1.0.11.tar.gz
Size 11.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d7c864d7c454fa8f402b0942f70334cbbf07f8d0862c74f32d8b2abbccfe3e3e
BLAKE2b-256 checksum
How to use checksums
458d9e68a1b60b466388ff99e21307bf51bdab2389626a849740d7f6b1f8af05
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.12

Release files / python_snake_game-1.0.11-py3-none-any.whl

Download URL python_snake_game-1.0.11-py3-none-any.whl
Size 10.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e5b43151bd80f7b00b2f10c3762aaee076bcc6efeb8b5ad2f95fb1ebbcb28e2e
BLAKE2b-256 checksum
How to use checksums
a2f92a0926246ce25ad7715bfa52e502990a342e290a8408b18d9a6421d0f1c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.12

Security for python-snake-game 1.0.11

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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