Skip to main content

Okey Solver Logo

Okey Solver

An enterprise-ready Python library for solving Okey & Rummikub board states, arranging hands, and processing layouts with computer vision pipelines.

tests Python support License


🏗 Modular Package Architecture

The codebase is split into fully decoupled, high-performance packages under the src/ directory:

  1. okey_core: Holds shared domain types (Tile, Meld, Arrangement, OrchestratorResult) and exceptions. Completely independent.
  2. okey_solver: Stateless mathematical engines to calculate optimal run/group melds and identical pairs. Uses slot-based DTO mapping (LightTile, LightMeld) to bypass Pydantic model loop overhead.
  3. okey_vision: Translates frames (numpy, PIL, bytes, base64) into tile predictions. Queries the cloud Roboflow Workflow API (including the pretrained Okey-Rummikub Model on Roboflow Universe trained on the Okey-Data Kaggle Dataset) to detect layouts. Decoupled from solver logic via an injectable LabelParserStrategy.
  4. okey_orchestrator: Orchestrates pipelines by feeding vision outputs into the mathematical solver. Supports passing custom SolverEngine instances or a strategy string directly during setup.
  5. okey_server: A microservice framework delivering endpoints for vision processing and hand arrangement.

📦 Installation

To install the core mathematical solver:

pip install okey-solver-py

To install computer vision extras:

pip install okey-solver-py[vision]

To install FastAPI server extras:

pip install okey-solver-py[server]

To install everything for development:

pip install okey-solver-py[vision,server]

💻 CLI Commands

The package exposes the following CLI commands:

  • okey-solve: Solves hand arrangements from lists of tile arguments.
  • okey-vision: Runs object detection predictions on an image layout using Roboflow workflows.
  • okey-serve: Launches the FastAPI REST microservice API.
  • okey-demo: Launches the local terminal solver demo application.

🚀 Quick Start

1. Basic Solver Arrangement

from okey_solver import create_standard_okey_solver, Tile, TileColor

# Instantiates a stateless, independent engine
solver = create_standard_okey_solver(strategy="backtracking")

tiles = [
    Tile(id="r5", color=TileColor.RED, value=5),
    Tile(id="r6", color=TileColor.RED, value=6),
    Tile(id="r7", color=TileColor.RED, value=7),
]
result = solver.find_best_arrangement(tiles)
print(f"Total Score: {result.totalScore}")

2. End-to-End Orchestration (Vision + Solver with Strategy Selection)

from okey_vision import RoboflowWorkflowProvider
from okey_orchestrator import VisionSolverEngine

# 1. Initialize vision model provider
provider = RoboflowWorkflowProvider(api_key="YOUR_ROBOFLOW_API_KEY")

# 2. Bind pipeline inside the orchestrator with strategy selection
# Supports strategy="backtracking", strategy="greedy", or passing a custom solver=instance
engine = VisionSolverEngine(pipeline=provider, strategy="greedy")

# 3. Analyze layout image and solve
result = engine.analyze_frame("board_layout.jpg")
print("Detected Tiles:", result.tiles)
print("Optimal Score:", result.arrangement.totalScore)

🌐 FastAPI Microservice (API Server)

Deploy this package directly to cloud infrastructure to process requests via HTTP:

Start the Microservice

# Set environment variables for Roboflow Workflow
export OKEY_RF_KEY="your_api_key"

# Start the uvicorn instance on port 8000
okey-serve --port 8000

Endpoints

  • POST /solver/arrange: Accepts a JSON list of tile parameters and returns arranged melds.
  • POST /vision/solve: Accepts an uploaded board image, detects the layout via Roboflow Workflows, and returns solved arrangements.
  • POST /vision/extract: Accepts an uploaded board image, detects and returns the list of Okey tiles.
  • Interactive Swagger Docs: Visit http://localhost:8000/docs to test requests in the browser.

📊 Capability Matrix

Feature Package Mode Capabilities
State Resolution okey_solver Sync Stateless backtracking and greedy hand-arranging meld solvers. Supports circular run checks and Joker resolutions.
Layout Detection okey_vision Async / Sync Multi-stage Roboflow Workflows querying, OCR labeling, confidence filters, and custom label mapping.
E2E Orchestration okey_orchestrator Async / Sync Feeds images directly into okey_vision and pipes outcomes into okey_solver dynamically.
FastAPI Microservice okey_server Async API exposing /vision/solve and /vision/extract with size (10MB) & MIME checks, instance registry caching, and safe error handling.

🗺 System Flow & Architecture

graph TD
    Client[Client / Caller] -->|1. HTTP Upload| Server[okey_server: API App]
    Server -->|2. validate_image_file| SizeCheck{MIME & 10MB Check}
    SizeCheck -->|Valid Image Bytes| DI[Depends: get_roboflow_workflow_provider]
    DI -->|3. Registry Cached Provider| Router[solve_vision Router]
    
    subgraph Vision Orchestration
        Router -->|4. analyze_frame_async| Orch[okey_orchestrator: VisionSolverEngine]
        Orch -->|5. detect_async| Providers[okey_vision: RoboflowWorkflowProvider]
        Providers -->|6. run_workflow| CloudAPI((Roboflow Workflow API))
        CloudAPI -->|7. Predictions JSON| Providers
        Providers -->|8. parse_tile| Parser[FuzzyLabelParser]
    end
    
    subgraph Mathematical Solver
        Parser -->|9. find_best_arrangement| Solver[okey_solver: SolverEngine]
        Solver -->|10. Meld Arrangements| Orch
    end
    
    Orch -->|11. OrchestratorResult| Router
    Router -->|12. JSON Response| Client

📖 Extended Documentation

  • 🧮 Solver Engines Guide - Mathematical formulations, algorithmic flowcharts (Greedy, Backtracking, Hybrid, ILP), and execution performance matrix.
  • 🏗 Architecture & Flow Reference - Visual flow pipelines, observers, and providers.
  • 📜 Game Rules Reference - Explanations of run configurations, circular sequences, and Joker/False Okey rules.
  • 💻 CLI Usage Guide - Terminal parameters for running predictions and solvers.
  • 🤝 Contributing Guide - Guidelines for configuring local poetry environments and running Ruff/Mypy checks.

Download files

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

Source Distribution

okey_solver_py-0.5.0.tar.gz (33.3 kB view details)

Uploaded Source

Built Distribution

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

okey_solver_py-0.5.0-py3-none-any.whl (44.1 kB view details)

Uploaded Python 3

File details

Details for the file okey_solver_py-0.5.0.tar.gz.

File metadata

  • Download URL: okey_solver_py-0.5.0.tar.gz
  • Upload date:
  • Size: 33.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for okey_solver_py-0.5.0.tar.gz
Algorithm Hash digest
SHA256 639cd0cebf1e5b02a470c26d9d669d2d7225c2346d93b9c06c3a5dbbf3609261
MD5 8da691953140bfedbe678d1bd583b370
BLAKE2b-256 4b6c0019e774be64797b69dfa6fc82aa34676fb085e9dbd8adaa97aa6f0c8466

See more details on using hashes here.

Provenance

The following attestation bundles were made for okey_solver_py-0.5.0.tar.gz:

Publisher: release.yml on AtaCanYmc/okey-solver-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file okey_solver_py-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: okey_solver_py-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 44.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for okey_solver_py-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 85ab32792e5ad122f638c8b458ff10bbe8896c5c51fd6a8404459969739341a0
MD5 4d51de2e37c4b7b17375bb6eed802174
BLAKE2b-256 3f409601f62d5b8f5eee8be8b28852142b04fd2c15dc162b2a7680f8442db8f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for okey_solver_py-0.5.0-py3-none-any.whl:

Publisher: release.yml on AtaCanYmc/okey-solver-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.6.0

2 files

This release

0.5.0 This release

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 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