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.3.0

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.3.0
File Size Uploaded Provenance
multiplayer-2.3.0.tar.gz 43.4 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 91.5 kB

Release files / multiplayer-2.3.0.tar.gz

Download URL multiplayer-2.3.0.tar.gz
Size 43.4 kB
Tags Source
SHA-256 checksum
How to use checksums
aee873facb54cacca74058c6683608d0ccf52c9a47abf42d1bebdc2feaa8c5b3
BLAKE2b-256 checksum
How to use checksums
09e2ce15214477b39e664fb9db2699aed0bf7d4a72edb2c301c40b3a2da0a0e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","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.3.0-py3-none-any.whl

Download URL multiplayer-2.3.0-py3-none-any.whl
Size 48.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ea60bde7a282fc21a6316d6180aaf5cc635e8edc98dd24ae592bfe0a6dbd2f42
BLAKE2b-256 checksum
How to use checksums
4965ee465e5b6366c2054d31aeb9bedc2fb8a42156e4303440e2366de6e21567
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","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.3.0

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