Skip to main content

pymultiplayer

A library for adding multiplayer functionality to python games.

Note

This is a work in progress. Don't expect all features to work. I don't know what version of python is needed for this package to work.

This is mainly just a passion project/project to help future projects (in fact I'm using it right now in Elemental Defense) but it would be nice if it had some use.


Usage

A full example of this package's usage will be uploaded to iamdeedz.github.io eventually (if I get around to it)!


Installation

pip install pymultiplayer or python -m pip install pymultiplayer


Client Representation

The client is represented by a class with the following attributes:

class _Client:
    def __init__(self, ws, id):
        self.ws = ws
        self.id = id

Parameters

  • ws - The websocket connection. Used for sending messages with ws.send().
  • id - The client's id. Used for identifying clients.

The client class is not meant to be initialized by the user. It is created by the server and passed to the message handler function.


MultiplayerClient

class MultiplayerClient:
    def __init__(self, msg_handler, ip="127.0.0.1", port=1300, auth_handler=None):

TCPMultiplayerServer

class TCPMultiplayerServer:
    def __init__(self, msg_handler, ip="127.0.0.1", port=1300, auth_func=None):

Parameters

  • msg_handler - The function that gets ran for every message the server receives. Takes in the message as the first argument and the client as the second. REQUIRED
  • ip - The ip address the server will run on. Default is localhost or 127.0.0.1.
  • port - The port the server will run on. Default is 1300.
  • auth_func - If you want to use authentication, you can pass a function here. If an auth_func is given, it will be run every time a client connects. Takes in the websocket connection. Take a look at this example. The auth code is in server.py and authenticator.py.

Usage

Full examples of these functions will be uploaded to iamdeedz.github.io in due course but for now, here's a basic example.

Let's start with the server.

First, create a file called server.py.

Now, create the required function(s).

# server.py

def msg_handler(msg, client):
    print(f"Received message from {client}: {msg}")

Then, create the server object.

# server.py

from pymultiplayer import TCPMultiplayerServer

def msg_handler(msg, client):
    print(f"Received message from {client}: {msg}")

server = TCPMultiplayerServer(msg_handler)

Next, run the server.

# server.py

from pymultiplayer import TCPMultiplayerServer

def msg_handler(msg, client):
    print(f"Received message from {client}: {msg}")

server = TCPMultiplayerServer(msg_handler)
server.run()

Metadata

Release files for pymultiplayer 0.3.6

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

Source distribution (sdist)

Source distribution for pymultiplayer 0.3.6
File Size Uploaded
pymultiplayer-0.3.6.tar.gz 9.9 kB Details

Built distribution (wheel)

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

Total release size: 20.0 kB

Release files / pymultiplayer-0.3.6.tar.gz

Download URL pymultiplayer-0.3.6.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f9fb1b64482f94f8854694f061f8ca6956d2edf50627552d6e6afdfc89c778f2
BLAKE2b-256 checksum
How to use checksums
d9a56aed02aeff3c785568257f362f345ecb12915b4d6a5b8b0dbf091c836758
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.2

Release files / pymultiplayer-0.3.6-py3-none-any.whl

Download URL pymultiplayer-0.3.6-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
944167205bdee260639fb8e3bfd685914de9048a3aa5ab8b0b51d68731a6a086
BLAKE2b-256 checksum
How to use checksums
d6178a5bf660e6893f27fca6a92c545696b28d72b4b583f3ae2cc681f5898972
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.2

Release history Release notifications | RSS feed

This release

0.3.6 This release

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3

2 release files

0.2

1 release file

0.1

2 release files

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