Skip to main content

Multiplayer Library V2

A Python library for managing multiplayer game sessions, users, and groups.

Features

  • Player Management: Create players with static and dynamic attributes.
  • User Accounts: Authentication and role-based permissions (Player, Group Admin, Server Admin).
  • Game Sessions: Support for turn-based and simultaneous games, private games with passwords, and observers.
  • Game Groups: Organize multiple games into manageable groups.
  • Persistence: Save and restore your game state using JSON or SQLite formats.
  • Networking: Client-Server architecture using TCP with optional TLS 1.3 encryption, automatic server discovery, and real-time notifications.
  • Name Suggestions: Built-in utility to suggest random names for players and games from various categories.

Installation

Install the library using pip:

pip install multiplayer

Alternatively, you can install it by downloading the .whl file from the Releases section of the GitHub repository:

pip install multiplayer-2.0.0-py3-none-any.whl

Quick Start

Creating a Player and User

from multiplayer.game import Player, User
from multiplayer import ParameterFamily

# Create a player with attributes
player = Player("Alice", score=(ParameterFamily.DYNAMIC, 0), team=(ParameterFamily.STATIC, "Red"))

# Create a user account associated with its own player profile
user = User(username="alice_92", password="secret_password", email="alice@example.com")

Managing Games

from multiplayer.game import Game
from multiplayer.utils import suggest_game_name

# Create a turn-based game with a suggested name
game_name = suggest_game_name("cities")
game = Game(name=game_name, turn_based=True)

# Join and start the game
game.join_game_as_player(player)
game.start()

Using Game Groups

from multiplayer.game import GameGroup

# Organize multiple games
group = GameGroup(name="Summer Tournament")
group.add_game(game)

Persistence

from pathlib import Path
from multiplayer.save import Save
from multiplayer import SaveFormat

# Initialize a save file (JSON or SQLite)
save_handler = Save(file_path=Path("savegame.json"), save_format=SaveFormat.JSON)

# Save an object
save_handler.save(game)
save_handler.flush()  # Effective write to disk

# Load objects
loaded_games = save_handler.load("Game")

Networking

Starting a Server

import asyncio
from multiplayer.server import GameServer

async def main():
    # Create and start a discoverable server
    server = GameServer(name="Battle Server", discoverable=True)
    await server.start()
    try:
        await asyncio.Event().wait()
    finally:
        await server.stop()

if __name__ == "__main__":
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        pass

Connecting a Client

from multiplayer.client import GameClient

# Connect to a server
client = GameClient(host="127.0.0.1")
try:
    client.connect()

    # Register a notification handler
    client.on_notification("GAME_EVENT", lambda p: print(f"Received event: {p}"))

    # Create a player for this client session
    player = client.create_player("Alice")
    print(f"Connected as {player.name}")
finally:
    client.disconnect()

For a command-line server, run uv run python scripts/run_server.py --help. Press CTRL+C to stop it cleanly.

Documentation

For more detailed information, please refer to:

Development

The project uses uv for dependency management.

# Install development dependencies
uv sync

# Run quality checks and tests
uv run python scripts/check_project.py
uv run pytest

License

See LICENSE.md for details.

Metadata

Release files for multiplayer 2.0.3

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

Source distribution (sdist)

Source distribution for multiplayer 2.0.3
File Size Uploaded Provenance
multiplayer-2.0.3.tar.gz 41.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for multiplayer 2.0.3
File Interpreter ABI Platform
multiplayer-2.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 88.1 kB

Release files / multiplayer-2.0.3.tar.gz

Download URL multiplayer-2.0.3.tar.gz
Size 41.7 kB
Tags Source
SHA-256 checksum
How to use checksums
fefd5aa28cdba78c36f14df6e653a689e97da62ea0cd2a8ecd7502d2f322e05c
BLAKE2b-256 checksum
How to use checksums
67b9b7d8665a047dc8377a1c73a9245c4a107674a7aa84111e10b433262913c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / multiplayer-2.0.3-py3-none-any.whl

Download URL multiplayer-2.0.3-py3-none-any.whl
Size 46.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e332a241a1eaf83caf3f1feb44993e2fee81541f4751fc4b92e98bbb24a5771
BLAKE2b-256 checksum
How to use checksums
727699473a391e3258518dd1efcaa41bf1881a6d420577518f52300e63cffd63
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for multiplayer 2.0.3

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.

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