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

Built distribution (wheel)

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

Total release size: 87.7 kB

Release files / multiplayer-2.0.1.tar.gz

Download URL multiplayer-2.0.1.tar.gz
Size 41.5 kB
Tags Source
SHA-256 checksum
How to use checksums
cf531ee698addc35636d52425e8a7bf98e05acaeff58f3294db3b365564377fa
BLAKE2b-256 checksum
How to use checksums
979905525bf641b1025e2c8c253a053723b4924c07970f4410a80981263f3393
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.1-py3-none-any.whl

Download URL multiplayer-2.0.1-py3-none-any.whl
Size 46.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8ebe617de57f922b2799f73da8bc00fc37cdd5ad8d900ab5415d3f645a1d20b8
BLAKE2b-256 checksum
How to use checksums
3b75016b23e33e7d82c25c3a9e55276eb2fed181aa769c2fef3bca89139e7004
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.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.

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