Diplomacy: DATC-Compliant Game Engine

This project contains an open-source DATC-compliant Diplomacy game engine, a client-server architecture for network play, a web interface to play against bots and to visualize games, and a DAIDE-compatible adapter to connect DAIDE bots to the server.
Documentation
The complete documentation is available at diplomacy.readthedocs.io.
Getting Started
Installation
The latest version of the package can be installed with:
pip install diplomacy
Version 1.2.0 includes engine and saved-game fixes, rendering improvements, and a refreshed web toolchain. See the changelog and release checklist.
Maintainer publishing uses GitHub Actions PyPI Trusted Publishing (OIDC), not a
local API token or .pypirc. The PyPI publisher fields are owner diplomacy,
repository diplomacy, workflow release.yml, environment release. Authorized
administrators must separately configure that publisher and the GitHub release
environment with required reviewers and version-tag deployment restrictions;
these settings are not configured by this repository change. A stable, non-draft
GitHub release.published event validates the exact v<PACKAGE_VERSION> tag and
then publishes after environment approval. workflow_dispatch only validates,
never publishes. See the release checklist before authorizing any tag, push, or upload.
The package retains its legacy Python >=3.5 metadata; Python 3.5 through 3.9 have not
been verified for this release. Current release validation targets Python 3.10 through
3.13; consult the release validation report for completed results rather than treating
this target as a compatibility guarantee. Use Python 3.12 for release preparation;
build-tool requirements do not establish tested runtime compatibility.
Development dependencies may require a newer interpreter still. The web toolchain
requires Node.js 22.13 or newer.
Running a game
The following script plays a game locally by submitting random valid orders until the game is completed.
import random
from diplomacy import Game
from diplomacy.utils.export import to_saved_game_format
# Creating a game
# Alternatively, a map_name can be specified as an argument. e.g. Game(map_name='pure')
game = Game()
while not game.is_game_done:
# Getting the list of possible orders for all locations
possible_orders = game.get_all_possible_orders()
# For each power, randomly sampling a valid order
for power_name, power in game.powers.items():
power_orders = [random.choice(possible_orders[loc]) for loc in game.get_orderable_locations(power_name)
if possible_orders[loc]]
game.set_orders(power_name, power_orders)
# Messages can be sent locally with game.add_message
# e.g. game.add_message(Message(sender='FRANCE',
# recipient='ENGLAND',
# message='This is a message',
# phase=self.get_current_phase(),
# time_sent=int(time.time())))
# Processing the game to move to the next phase
game.process()
# Exporting the game to disk to visualize (game is appended to file)
# Alternatively, we can do >> file.write(json.dumps(to_saved_game_format(game)))
to_saved_game_format(game, output_path='game.json')
Web interface
It is also possible to install a web interface in React to play against bots and/or other humans and to visualize games.
The web interface can be installed with:
# Install NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
# Clone repo
git clone https://github.com/diplomacy/diplomacy.git
# Install package locally
# You may want to install it in a conda or virtualenv environment
cd diplomacy/
pip install -r requirements_dev.txt
# Use Node.js 22.13 or newer (for example, nvm install 22 && nvm use 22).
# Install the locked frontend dependencies.
cd diplomacy/web
npm ci
# In a terminal window or tab - Launch the Vite development server
npm start
# In another terminal window or tab - Launch diplomacy server
python -m diplomacy.server.run
The web interface will be accessible at http://localhost:3000. The development server uses that port strictly and fails if it is already in use.
From diplomacy/web, run npm test -- --runInBand for the Jest tests,
npm run lint for ESLint, and npm run build to create the production site in build/.
Use npm run preview to preview that build locally (not as a production server).
The build uses relative asset URLs, so it can be served at a subdirectory as well as the site root.
The Vite build targets modern browsers: Chrome/Edge 111+, Firefox 114+, and Safari 16.4+. This replaces the previous Create React App Browserslist targets; older browsers are no longer supported.
To login, users can use admin/password or username/password. Additional users can be created by logging in with a username that does not exist in the database.
Visualizing a game
It is possible to visualize a game by using the "Load a game from disk" menu on the top-right corner of the web interface.
Network Game
It is possible to join a game remotely over a network using websockets. The script below plays a game over a network.
Note. The server must be started with python -m diplomacy.server.run for the script to work.
import asyncio
import random
from diplomacy.client.connection import connect
from diplomacy.utils import exceptions
POWERS = ['AUSTRIA', 'ENGLAND', 'FRANCE', 'GERMANY', 'ITALY', 'RUSSIA', 'TURKEY']
async def create_game(game_id, hostname='localhost', port=8432):
""" Creates a game on the server """
connection = await connect(hostname, port)
channel = await connection.authenticate('random_user', 'password')
await channel.create_game(game_id=game_id, rules={'REAL_TIME', 'NO_DEADLINE', 'POWER_CHOICE'})
async def play(game_id, power_name, hostname='localhost', port=8432):
""" Play as the specified power """
connection = await connect(hostname, port)
channel = await connection.authenticate('user_' + power_name, 'password')
# Waiting for the game, then joining it
while not (await channel.list_games(game_id=game_id)):
await asyncio.sleep(1.)
game = await channel.join_game(game_id=game_id, power_name=power_name)
# Playing game
while not game.is_game_done:
current_phase = game.get_current_phase()
# Submitting orders
if game.get_orderable_locations(power_name):
possible_orders = game.get_all_possible_orders()
orders = [random.choice(possible_orders[loc]) for loc in game.get_orderable_locations(power_name)
if possible_orders[loc]]
print('[%s/%s] - Submitted: %s' % (power_name, game.get_current_phase(), orders))
await game.set_orders(power_name=power_name, orders=orders, wait=False)
# Messages can be sent with game.send_message
# await game.send_game_message(message=game.new_power_message('FRANCE', 'This is the message'))
# Waiting for game to be processed
while current_phase == game.get_current_phase():
await asyncio.sleep(0.1)
# A local copy of the game can be saved with to_saved_game_format
# To download a copy of the game with messages from all powers, you need to export the game as an admin
# by logging in as 'admin' / 'password'
async def launch(game_id):
""" Creates and plays a network game """
await create_game(game_id)
await asyncio.gather(*[play(game_id, power_name) for power_name in POWERS])
if __name__ == '__main__':
asyncio.run(launch(game_id=str(random.randint(1, 1000))))
License
This project is licensed under the APGLv3 License - see the LICENSE file for details
Metadata
Release files for diplomacy 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| diplomacy-1.2.0.tar.gz | 2.5 MB | With provenance | Details for diplomacy-1.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| diplomacy-1.2.0-py3-none-any.whl | Python 3 | none | any | Details for diplomacy-1.2.0-py3-none-any.whl |
Total release size: 4.4 MB
Release files / diplomacy-1.2.0.tar.gz
| Download URL | diplomacy-1.2.0.tar.gz |
|---|---|
| Size | 2.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c48af9d61ca149e0c26392243c2409496ffb0e8b0cb046286e5a92aa7980e4f5
|
|
BLAKE2b-256 checksum How to use checksums |
a7e929ecbd3d12f83fe9414b24861473f9d547740b5adfcd64092989d871b0e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logRelease files / diplomacy-1.2.0-py3-none-any.whl
| Download URL | diplomacy-1.2.0-py3-none-any.whl |
|---|---|
| Size | 1.8 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
49079ac05ccca8bf7abd8ade4a86ebabbccd3684675ab8ff31ce528be5f48564
|
|
BLAKE2b-256 checksum How to use checksums |
0b88bad1dd09e87b653b6e493b585b7730c442422860750c14d5541145f53a41
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logSecurity for diplomacy 1.2.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for diplomacy-1.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logA 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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.