Skip to main content

pymahjong

PyPI version Python versions License Documentation Build Status

A Japanese Riichi Mahjong environment for decision AI research, featuring a high-performance C++ backend with Python bindings.

Features

  • Complete Rule Implementation - Full Japanese Riichi Mahjong rules including all standard yaku
  • Gymnasium Compatible - Ready-to-use single-agent environment with pretrained opponents
  • Multi-agent Support - 4-player environment for multi-agent research
  • Oracle Observation - Access to hidden information (opponents' hands) for oracle-guided learning
  • High Performance - C++ game engine with efficient Python bindings via pybind11
  • Cross-platform - Pre-built wheels for Linux, macOS, and Windows (Python 3.10-3.14)

Installation

pip install pymahjong

Verify the installation:

import pymahjong
pymahjong.test()

Quick Start

Single-Agent Environment

Play against 3 opponents with a gym-like interface:

import pymahjong
import numpy as np

env = pymahjong.SingleAgentMahjongEnv(opponent_agent="random")
obs = env.reset()

while True:
    valid_actions = env.get_valid_actions()
    action = np.random.choice(valid_actions)
    obs, reward, done, _ = env.step(action)
    
    if done:
        print(f"Game over! Payoff: {reward}")
        break

Multi-Agent Environment

4 agents compete in a full game:

import pymahjong
import numpy as np

env = pymahjong.MahjongEnv()

for game in range(10):
    env.reset()
    
    while not env.is_over():
        pid = env.get_curr_player_id()
        valid_actions = env.get_valid_actions()
        obs = env.get_obs(pid)
        
        action = np.random.choice(valid_actions)
        env.step(pid, action)
    
    print(f"Game {game}: payoffs = {env.get_payoffs()}")

Documentation

Full documentation is available at https://agony5757.github.io/mahjong/

Pretrained Models

Pretrained opponent models are available from the GitHub releases:

env = pymahjong.SingleAgentMahjongEnv(opponent_agent="path/to/model.pth")

Offline Dataset

Human demonstration data from Tenhou.net (6 dan+ players) is available for offline RL research. Download from releases.

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

Citing

If you use pymahjong in your research, please cite:

@inproceedings{han2022variational,
  title     = {Variational Oracle Guiding for Reinforcement Learning},
  author    = {Dongqi Han and Tadashi Kozuno and Xufang Luo and Zhao-Yun Chen 
               and Kenji Doya and Yuqing Yang and Dongsheng Li},
  booktitle = {International Conference on Learning Representations},
  year      = {2022},
  url       = {https://openreview.net/forum?id=pjqqxepwoMy}
}

License

This project is licensed under the Apache License 2.0.

Contact

Metadata

Release files for pymahjong 1.1.2

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

Source distribution (sdist)

Source distribution for pymahjong 1.1.2
File Size Uploaded Provenance Actions
pymahjong-1.1.2.tar.gz 2.4 MB With provenance Details for pymahjong-1.1.2.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for pymahjong 1.1.2
File Actions
pymahjong-1.1.2-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for pymahjong-1.1.2-cp312-cp312-win_amd64.whl
pymahjong-1.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details for pymahjong-1.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
pymahjong-1.1.2-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details for pymahjong-1.1.2-cp312-cp312-macosx_11_0_arm64.whl
pymahjong-1.1.2-cp312-cp312-macosx_10_9_x86_64.whl CPython 3.12 CPython 3.12 macOS 10.9+ x86-64 Details for pymahjong-1.1.2-cp312-cp312-macosx_10_9_x86_64.whl
pymahjong-1.1.2-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details for pymahjong-1.1.2-cp311-cp311-win_amd64.whl
pymahjong-1.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details for pymahjong-1.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
pymahjong-1.1.2-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details for pymahjong-1.1.2-cp311-cp311-macosx_11_0_arm64.whl
pymahjong-1.1.2-cp311-cp311-macosx_10_9_x86_64.whl CPython 3.11 CPython 3.11 macOS 10.9+ x86-64 Details for pymahjong-1.1.2-cp311-cp311-macosx_10_9_x86_64.whl
pymahjong-1.1.2-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details for pymahjong-1.1.2-cp310-cp310-win_amd64.whl
pymahjong-1.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details for pymahjong-1.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
pymahjong-1.1.2-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details for pymahjong-1.1.2-cp310-cp310-macosx_11_0_arm64.whl
pymahjong-1.1.2-cp310-cp310-macosx_10_9_x86_64.whl CPython 3.10 CPython 3.10 macOS 10.9+ x86-64 Details for pymahjong-1.1.2-cp310-cp310-macosx_10_9_x86_64.whl

Total release size: 8.6 MB

Release files / pymahjong-1.1.2.tar.gz

Download URL pymahjong-1.1.2.tar.gz
Size 2.4 MB
Tags Source
SHA-256 checksum
How to use checksums
b863bffa95826714d0f6539ea87265dd91af3786b6ee628aa63ef5a8ec236c82
BLAKE2b-256 checksum
How to use checksums
a2ae3c2fdd5a629ac715e5898d56faa5055fbf82137b54e00c6fe642f961e920
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Apr 22, 2026.

Transparency log

Release files / pymahjong-1.1.2-cp312-cp312-win_amd64.whl

Download URL pymahjong-1.1.2-cp312-cp312-win_amd64.whl
Size 425.2 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
3c025190d12ceb97b44406e86add4eadf079c3df56abd6ee0706273128eca143
BLAKE2b-256 checksum
How to use checksums
7a730466bbb88b1ac1ed2513e9009bbaa0a638681cb5c07b4bb63cfa215f5c3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Apr 22, 2026.

Transparency log

Release files / pymahjong-1.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pymahjong-1.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 602.2 kB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
c5f0eda02d0c88224f7cf1aa0d59c3397693f438174b6206526b5e04980ffbbd
BLAKE2b-256 checksum
How to use checksums
12f0eb4b1e9ae74d181d2277992d8f3711b4c8f66dd3c6495ce49bc830bf7d19
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Apr 22, 2026.

Transparency log

Release files / pymahjong-1.1.2-cp312-cp312-macosx_11_0_arm64.whl

Download URL pymahjong-1.1.2-cp312-cp312-macosx_11_0_arm64.whl
Size 492.8 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
0bf470b8959d6aa5a339aeccfd4a31428a17d2593a4048df834af846d043052a
BLAKE2b-256 checksum
How to use checksums
de89e738ac879b5eb8ec5a85e544d28a4db83c09f9e292eaf5a9324f495824be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Apr 22, 2026.

Transparency log

Release files / pymahjong-1.1.2-cp312-cp312-macosx_10_9_x86_64.whl

Download URL pymahjong-1.1.2-cp312-cp312-macosx_10_9_x86_64.whl
Size 540.5 kB
Tags CPython 3.12 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
a4e4556136745a38e6a84b3d232c9a448d888cd0a0dd5c86f7922f0b3c5e765f
BLAKE2b-256 checksum
How to use checksums
2ceca71362dcd051080e77d81e2199e8e8ae6149fb841e738883221e5abbae8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Apr 22, 2026.

Transparency log

Release files / pymahjong-1.1.2-cp311-cp311-win_amd64.whl

Download URL pymahjong-1.1.2-cp311-cp311-win_amd64.whl
Size 423.1 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
be5163b4020521a0a93fa8cdc93cf99bcb556b9cdb6bc761d67dfc63a095a181
BLAKE2b-256 checksum
How to use checksums
ba09e1e14ce26bf449455bc71f979a7857d17938ffdfa8da2728f5999873e580
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Apr 22, 2026.

Transparency log

Release files / pymahjong-1.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pymahjong-1.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 602.3 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
a08e467c381fd5b63fb4ab42ebfa0237b2a3f6f413e6c027f5f1efa8dc4f4f41
BLAKE2b-256 checksum
How to use checksums
329eb46cc7fe3bdccbb4741f6875b457ce55b77018e6fedbadfa2565eab768e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Apr 22, 2026.

Transparency log

Release files / pymahjong-1.1.2-cp311-cp311-macosx_11_0_arm64.whl

Download URL pymahjong-1.1.2-cp311-cp311-macosx_11_0_arm64.whl
Size 490.1 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e150c2afb3c61aa7f22988f4e25d90d042df234402f3d27b54985cbf8d1afc12
BLAKE2b-256 checksum
How to use checksums
16e401de4aae0f240c1d42337cdea6954864e2c43d592a6408e0a9d48adc50d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Apr 22, 2026.

Transparency log

Release files / pymahjong-1.1.2-cp311-cp311-macosx_10_9_x86_64.whl

Download URL pymahjong-1.1.2-cp311-cp311-macosx_10_9_x86_64.whl
Size 533.6 kB
Tags CPython 3.11 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
b1d57b23cdcee826d01f9a45ecd7d6b0090995e18b6c101c59e118e41174b1e5
BLAKE2b-256 checksum
How to use checksums
941577e5dc1fe648f7f080866197b312094d4f1ec9acd1cf4b001e3763a6b151
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Apr 22, 2026.

Transparency log

Release files / pymahjong-1.1.2-cp310-cp310-win_amd64.whl

Download URL pymahjong-1.1.2-cp310-cp310-win_amd64.whl
Size 422.3 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
35b6b54f33e5644eefbd2941c5e799c4a8ed41a0acd7f7cd047a9f436f3c6215
BLAKE2b-256 checksum
How to use checksums
0c24b34035e149383ad75617f073fc48b871377aa2397f058ed5e97e33b4ccc5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Apr 22, 2026.

Transparency log

Release files / pymahjong-1.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pymahjong-1.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 600.8 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
7dd85f571be1e5df8b1b1fb1af143b815b5f7457b96e3b29c31575d8d61a164a
BLAKE2b-256 checksum
How to use checksums
ea42bfbba1e3625be63e8fd81706ecdcb97be9ad6390ad1283144338551c6aa5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Apr 22, 2026.

Transparency log

Release files / pymahjong-1.1.2-cp310-cp310-macosx_11_0_arm64.whl

Download URL pymahjong-1.1.2-cp310-cp310-macosx_11_0_arm64.whl
Size 488.8 kB
Tags CPython 3.10 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
3e023bfbb94550939d3978f1b375beccfe1852b41a7f5f09b69f5053be77ef87
BLAKE2b-256 checksum
How to use checksums
ff43137e035ed7b1d2667f6697edb2af04446555276cde6318d3d99e3f6d3b8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Apr 22, 2026.

Transparency log

Release files / pymahjong-1.1.2-cp310-cp310-macosx_10_9_x86_64.whl

Download URL pymahjong-1.1.2-cp310-cp310-macosx_10_9_x86_64.whl
Size 532.2 kB
Tags CPython 3.10 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
c61ac898f0c05779d227258dc9202fea23f43ef3b3a7f7056eb72cbf2dd7c694
BLAKE2b-256 checksum
How to use checksums
67c0968ab7128cf86fca299b42382d5c7ea59dbee6e79bd56130934c87c0c03a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Apr 22, 2026.

Transparency log

Security for pymahjong 1.1.2

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

All 13 files in this release have been uploaded with provenance metadata.

Select from 13 files

Attestation for pymahjong-1.1.2.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 Apr 22, 2026.

Transparency log

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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