# Host a Python WebSocket game server: what to prepare

> Our servers run Python 3.12, but they never install packages, so your libraries have to travel inside the upload as wheels built for Linux. One command prepares them on your own computer. It is built and tested locally; no Python game has run on our servers yet.

*NetCraftGames (NCG) by Charging Bull Software. Last updated: 2026-10-03. Canonical page: https://netcraftgames.com/guides/python-websocket-server/*

## The short answer

In your project folder run `ncg pack . --python --install`, then `ncg check .ncg/build` and `ncg submit`. The first command downloads wheels for Linux x86-64 and Python 3.12 only, writes them into a `vendor` folder, adds a start script named `server`, and packs everything. It installs nothing unless you pass `--install`, and it never touches your own virtual environment.

## What the host provides

- **Python 3.12 and the standard library.** Nothing else. There is no pip on the servers and no network install at start.
- **Your libraries, as wheels.** The command asks for `cp312` and `manylinux` x86-64 wheels with no source builds (`--only-binary=:all:`), so no library is compiled and no install script runs. `ncg` also refuses, before pip starts, any `requirements.txt` line that is a folder, a web address, a repository or a pip option such as `--index-url` or `--no-binary`, because pip would build those with their own build code on your computer. Use plain lines such as `websockets==14.1`; pip is given a cleaned copy.
- **A start script named `server`.** It sets `PYTHONPATH` to your `vendor` folder, then runs your file with `python3`. Your manifest's command is that script.
- **Ubuntu 24.04**, so shipped Linux libraries must not need a newer glibc than 2.39.

## Steps

1. **List every library in `requirements.txt`**, pinned if you can.
2. **Listen on `0.0.0.0`** and read the port from the environment with a default.
3. **Add a health route and a join check** that answers with a known reply. The [Python prompt](https://netcraftgames.com/can-you-host-my-game/prompts/python-ws-hosting-basics/) makes your AI add them, and the clean stop on SIGTERM.
4. **Run `ncg init .`**, then `ncg pack . --python --install`, then `ncg check .ncg/build`.

## If your WebSocket is not at the root path

A FastAPI or Starlette route such as `/ws` is not the root. Declare it in `ncg.json` as `"wsPath": "/ws"`. The path is fixed by you at release. A player's path and query never reach your server. See the [Node guide](https://netcraftgames.com/guides/node-websocket-server/) for the allowed characters.

## What does not work

- **A library with no Linux wheel.** If a package only ships source, `--only-binary` stops with the package named. Pick a version that has a wheel, or another library.
- **Extensions built for Windows, macOS, ARM or Alpine.** Only `cp312` `manylinux` x86-64 is accepted.
- **Designs that need a plain web request before the WebSocket.** The gateway passes WebSocket connections only, so long polling and HTTP matchmaking do not work.
- **A source folder.** A project with `requirements.txt` and no vendored packages is held with the command to run.

## Mistakes that waste the most time

| Mistake | What you see | Fix |
| --- | --- | --- |
| Zipped your own virtual environment | Windows or macOS extensions refused | Run `ncg pack --python --install` instead |
| Wheel for Python 3.11 | Wheel for another system | The host runs 3.12; install for 3.12 |
| Missing `requirements.txt` entry | Import error at start | Add it and pack again |
| Listening on `127.0.0.1` | Health check never passes | Bind `0.0.0.0` |

## Frequently asked questions


### Does NetCraftGames run pip for me?

No. Nothing on our servers installs packages. `ncg pack . --python --install` downloads Linux wheels on your computer and puts them in the archive.

### Can I use FastAPI?

A FastAPI WebSocket route works, with the route declared as the WebSocket path. It was run through the gateway locally with uvicorn. Plain web endpoints beyond the health and join checks are not served to players.

### Is there a Python game running on NetCraftGames today?

Not yet. The preparation, the checks and the path setting are built and tested locally with real libraries, but no Python game has run on our servers, and nothing here is certified.

## Sources

- [MDN: WebSockets API](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API), accessed 2026-10-03

## Related pages

- [Hosting a browser WebSocket (WSS) game server](https://netcraftgames.com/engines/browser-websocket/): Host an existing authoritative browser game server on NetCraftGames: a Node 24, Python 3.12 or Linux x64 WebSocket server behind a wss gateway.
- [Host a Node.js WebSocket game server: what to prepare](https://netcraftgames.com/guides/node-websocket-server/): Get a Node.js 24 WebSocket game server ready for NetCraftGames: the one command that packs it, the WebSocket path setting, socket.io and what does not work.
- [What a connection config file must contain](https://netcraftgames.com/guides/connection-config-file-contents/): What a deployment manifest and a player connection config must contain for a hosted multiplayer server, with a real example and the rules that cause rejections.
