treys
raw JSON → 0.1.8 verified Fri May 01 auth: no python
treys is a pure Python poker hand evaluation library. It provides fast evaluation of 5-, 6-, and 7-card poker hands, as well as deck and card utilities. Current version 0.1.8 is stable with low release cadence.
pip install treys Common errors
error AttributeError: module 'treys' has no attribute 'Card' ↓
cause Old import pattern 'import treys' and then 'treys.Card' does not work because Card is not automatically imported. The library uses explicit submodule imports.
fix
Use 'from treys import Card' instead of 'import treys'.
error ValueError: The card '10h' could not be interpreted ↓
cause Hand string '10h' is invalid; treys expects single-character ranks (2-9, T, J, Q, K, A) and suits (h, d, c, s). Ten is represented as 'Th'.
fix
Use 'Th' for ten of hearts. For full card string, e.g., 'Ah' for Ace of hearts.
Warnings
gotcha Card objects printed as strings show a representation like 'Ah' (Ace of hearts), but for input use Card.new('Ah') or Card.from_str('Ah'). ↓
fix Use Card.new or Card.from_str to create cards from string, not the Card constructor directly.
breaking In version 0.1.6 and earlier, the import path was 'treys.card', 'treys.deck', 'treys.evaluator'. In 0.1.7+ the public API changed to import from 'treys' directly. ↓
fix Use 'from treys import Card, Deck, Evaluator' instead of deep imports.
deprecated The method evaluator.get_rank_class() returns an integer; evaluator.class_to_string() converts it to a human-readable rank string. There is no plan to remove but usage is stable. ↓
fix No action needed; just be aware of the two-step process to get a rank string.
Imports
- Card wrong
from treys.card import Cardcorrectfrom treys import Card - Deck wrong
from treys.deck import Deckcorrectfrom treys import Deck - Evaluator wrong
from treys.evaluator import Evaluatorcorrectfrom treys import Evaluator
Quickstart
from treys import Card, Deck, Evaluator
deck = Deck()
board = deck.draw(5)
hand = deck.draw(2)
evaluator = Evaluator()
rank = evaluator.evaluate(board, hand)
print("Hand rank:", evaluator.class_to_string(evaluator.get_rank_class(rank)))
print("Hand description:", evaluator.get_hand_description(board, hand))