Skip to main content

spielviz

PyPI License: MIT Python 3.9+ CI

Python visualization library for OpenSpiel game trees, information sets, and strategy profiles.

Installation

pip install spielviz

Quick Start

import spielviz

# One-liner: render any OpenSpiel game
spielviz.quick_render("kuhn_poker", path="kuhn.png")

Or with more control:

import pyspiel
import spielviz

game = pyspiel.load_game("kuhn_poker")
root = spielviz.build_tree(game)
root = spielviz.layout_tree(root)

# Highlight information sets
colors = spielviz.auto_color_info_sets(root, player=0)
fig, ax = spielviz.render_tree(
    root,
    highlight_info_sets=colors,
    show_actions=True,
    show_payoffs=True,
    title="Kuhn Poker",
)
fig.savefig("kuhn_poker.png", dpi=150, bbox_inches="tight")

Features

Game Tree Rendering

Render any OpenSpiel game as a publication-quality tree diagram:

  • Player-colored nodes (colorblind-friendly palette)
  • Action labels on edges
  • Terminal payoffs displayed
  • Chance node probabilities

Information Set Visualization

Highlight which nodes a player cannot distinguish:

colors = spielviz.auto_color_info_sets(root, player=0)
fig, ax = spielviz.render_tree(root, highlight_info_sets=colors)

# Or draw dashed connection lines (standard game theory notation)
spielviz.draw_info_set_connections(ax, root, player=0)

Strategy Profile Visualization

Visualize policies from CFR, fictitious play, or any OpenSpiel algorithm:

from open_spiel.python.algorithms import cfr

solver = cfr.CFRSolver(game)
for _ in range(1000):
    solver.evaluate_and_update_policy()
policy = solver.average_policy()

# Bar chart of action probabilities at each info set
fig, ax = spielviz.plot_strategy_profile(game, policy, player=0)

# Strategy overlaid directly on the game tree
fig, ax = spielviz.plot_strategy_on_tree(root, game, policy, player=0)

Large Game Support

Use max_depth for games with large state spaces:

spielviz.quick_render("tic_tac_toe", max_depth=3, path="ttt.png")

API Reference

Function Description
build_tree(game, max_depth=None) Build a TreeNode hierarchy from an OpenSpiel game
layout_tree(root, algorithm="simple") Compute (x, y) positions for all nodes
collect_info_sets(root) Group nodes by information state string
render_tree(root, **kwargs) Render game tree as matplotlib figure
save_tree(root, path, **kwargs) Render and save to file (PNG, SVG, PDF)
auto_color_info_sets(root, player) Assign distinct colors to info sets
draw_info_set_connections(ax, root, player) Draw dashed lines between info set nodes
plot_strategy_profile(game, policy, player=0) Bar chart of strategy at each info set
plot_strategy_on_tree(root, game, policy, player=0) Mini bar charts overlaid on tree
quick_render(game_name, **kwargs) One-liner convenience function

Tested Games

  • kuhn_poker — 2-player Kuhn Poker
  • leduc_poker — 2-player Leduc Poker (depth-limited)
  • tic_tac_toe — Tic-Tac-Toe (depth-limited)

Contributing

Contributions welcome! Please open an issue or PR.

git clone https://github.com/kvr06-ai/spielviz.git
cd spielviz
pip install -e ".[dev]"
pytest tests/
ruff check src/

License

MIT

Release files for spielviz 0.1.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 spielviz 0.1.1
File Size Uploaded
spielviz-0.1.1.tar.gz 860.8 kB Details

Built distribution (wheel)

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

Total release size: 873.0 kB

Release files / spielviz-0.1.1.tar.gz

Download URL spielviz-0.1.1.tar.gz
Size 860.8 kB
Tags Source
SHA-256 checksum
How to use checksums
7aa4aa94a2ea1c3fcf88f6706657a3917861a68518c609f4228edefb6b28ff27
BLAKE2b-256 checksum
How to use checksums
4f0d324f6a762e3f85f94c5b3f71a419a083ab5e66edb60a3c5a1650efd4c698
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Mar 19, 2026.

Transparency log

Release files / spielviz-0.1.1-py3-none-any.whl

Download URL spielviz-0.1.1-py3-none-any.whl
Size 12.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8f63424bc6dad2d0501ea206d903dc083adcef1cc78ce9492b5080abc4a5b03b
BLAKE2b-256 checksum
How to use checksums
5416645a60d7d290b8fe3274736706168fc478a572109c5a8906dbfe07030ff5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Mar 19, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

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