Skip to main content

Play poker against agents in your terminal, or use the engine to build your own poker agents app.

Project description

OpenPoker

PyPI version Python 3.10+ License: MIT

A Python poker engine (with a terminal UI) for building LLM poker apps, servers, and custom interfaces. Play against LLMs from OpenAI, Anthropic, and Openrouter.

Terminal UI

Play Texas Hold'em No-Limit against agents directly in your terminal:

  • Agent memory allows agents to store insights and observations at the end of each hand, learning opponent playing styles and carrying knowledge from one hand to another within a game session
  • Player personalities can be configured to create distinct playing styles and behaviors for each agent
  • Model selection supports OpenAI, Anthropic, and OpenRouter models, letting you mix different LLM providers at the same table
  • Agent rationales are produced for every decision and can be viewed in debug mode, showing the reasoning behind each action
  • Tool-based decisions use function calling to structure agent actions, with game state presented through context assembly that includes hand strength, pot odds, opponent behaviors, and historical insights
  • Monte Carlo simulation using Treys provides agents with win probability statistics to inform their decision-making and increase gameplay difficulty
  • Pot odds and EV calculations are automatically computed and available to agents for more strategic play
  • Type-safe implementation with full type hints and Pydantic models throughout

Quick Install

pip install openpoker

Run the Terminal UI

openpoker

Or with debug mode:

openpoker --debug

The terminal will prompt for API keys if needed, or you can create a .env file:

OPENAI_API_KEY=your_openai_key
ANTHROPIC_API_KEY=your_anthropic_key
OPENROUTER_API_KEY=your_openrouter_key

Development Install

git clone https://github.com/philippe-page/openpoker.git
cd openpoker
python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -e ".[dev]"

OpenPoker Engine

OpenPoker's terminal UI runs on a standalone engine designed as a library for building LLM-powered poker applications. The engine is built on PokerKit for game state and rule enforcement, and uses Treys for fast Monte Carlo simulations. The event-driven architecture makes it suitable for building servers, web applications with SSE or WebSocket transports, custom clients, or integrating poker gameplay into larger systems.

The engine handles game state, rule enforcement, agent decision orchestration, and emits granular events for every game action. Build React frontends, multiplayer servers, training environments, or any poker application on top of the same engine that powers the terminal UI.

Engine quickstart

from openpoker import (
    AIProvider, ActionType, EngineOptions, GameConfig,
    PlayerConfig, PlayerType, PokerAction, PokerEngine,
)

engine = PokerEngine(
    options=EngineOptions(enable_memory=True, enable_monte_carlo=True)
)

game_id = engine.create_game(
    game_name=table_name,
    config=GameConfig(small_blind=small_blind, big_blind=big_blind, starting_stack=buy_in),
    players=[
        PlayerConfig(id=user_id, name=display_name, player_type=PlayerType.HUMAN),
        PlayerConfig(id=agent_id, name=agent_name, player_type=PlayerType.AI, provider=provider, model=model),
    ],
)

snapshot = engine.start_hand(game_id)

while snapshot.hand_active:
    if snapshot.current_actor_id == user_id:
        available = engine.get_available_actions(game_id, user_id)
        action = get_action_from_client(available)
        snapshot = await engine.submit_action(game_id, user_id, action)
    else:
        snapshot = await engine.step(game_id)

Events and app integration

Subscribe once, then push events to whatever transport your app uses (SSE, websocket, queue, logs).

def on_event(event):
    data = event.model_dump(mode="json")
    print(event.event_type.value, data["sequence"])

unsubscribe = engine.subscribe(on_event)

Event types:

  • game_created - New game initialized with players
  • hand_started - New hand dealt, blinds posted
  • action_required - Player needs to act, includes available actions
  • action_applied - Player action processed (fold, check, call, bet, raise)
  • street_changed - Flop, turn, or river dealt
  • showdown - Hand complete, winners determined
  • player_eliminated - Player out of chips
  • game_over - Single player remains
  • ai_decision - AI agent decision with rationale and metadata
  • engine_error - Error occurred during game processing

Snapshots

Use snapshots as read-model state for clients:

snapshot = engine.get_snapshot(game_id, viewer_id=user_id)

Tutor/admin view can reveal all hole cards:

snapshot = engine.get_snapshot(game_id, reveal_all_hole_cards=True)

Agent payloads

Agent decisions return normalized metadata including:

  • provider and model
  • rationale
  • tool call name and arguments
  • token usage details (input/output/total, provider-specific fields when available)

Examples

See examples/:

  • examples/server_like_loop.py
  • examples/api_style_session.py
  • examples/sse_event_stream.py

Documentation

Testing

Run the full test suite:

python -m unittest discover -s tests -p "test_*.py" -v

Current coverage so far includes 200+ tests covering:

  • Poker game logic and rules
  • Engine orchestration
  • Event system
  • Monte Carlo simulation
  • Pot odds calculations
  • Snapshot visibility
  • TUI rendering
  • Elimination logic
  • LLM token usage tracking and validation

Contributing

See CONTRIBUTING.md for development setup and guidelines.

License

MIT - See LICENSE for details.

Changelog

See CHANGELOG.md for version history.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openpoker-0.0.1.tar.gz (34.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openpoker-0.0.1-py3-none-any.whl (37.0 kB view details)

Uploaded Python 3

File details

Details for the file openpoker-0.0.1.tar.gz.

File metadata

  • Download URL: openpoker-0.0.1.tar.gz
  • Upload date:
  • Size: 34.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for openpoker-0.0.1.tar.gz
Algorithm Hash digest
SHA256 6621e0d7d39a9fac200f9d233444064ac1167ffb3fa64234bd187970a807d940
MD5 ed1b182bb93d813731021ae67da4dae9
BLAKE2b-256 d1c9afc35d4f1bd15fa4d15f9523dd25fa767ddd03d923a4cac3e85376b64dcb

See more details on using hashes here.

File details

Details for the file openpoker-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: openpoker-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 37.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for openpoker-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ac7c562b5511162ddc4535c233f046b19a08729a99ae2e8b6e11a9acdc4a0160
MD5 6aeee45e821d58ab172ceb558a3a7f2d
BLAKE2b-256 707afed9d3e3db02a3ca4846af33d1e86c0c36dd3c3de62a0eec0be9fa57ef98

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page