Poker Cards documentation – Represent cards, decks and hands

class, suit=None)

Represents a single french-design card with it’s rank and suit.

Cards can be compared and ordered by rank. A card, relative to a card of the same rank but different suit, is compared as neither higher, lower nor equal.

  • rank (str) – Either the rank (one of ‘A’, ‘K’, ‘Q’, ‘J’, ‘T’, ‘9’, ... ‘2’) or rank and suit together (e.g. ‘AS’, ‘8H’, etc.)
  • suit (str) – The suit, if not given as one string with rank (one of ‘S’, ‘H’, ‘C’, ‘D’ for spade, heart, club or diamond)
Raises :


classmethod card_list(*args)

Create a list of new cards.

Each argument should describe one card with rank and suit together.

Parameters:args – One or more cards.
Returns:List of new cards, one for each input parameter.
Return type:list of objects
Raises :ValueError

Represents a single deck of 52 card.Card objects.

The deck could be imagined face down on a table. All internal lists represent the cards in order from bottom up. So dealing the top card means poping last item from the list.


Deal the top card from the deck. instance

Shuffle the deck.

class, evaluate=True)

Compute the best hand from given cards, implementing traditional “high” poker hand ranks.

The hand object can be given more than five cards (as in Texas Hold’em or similar variants) and the evaluation will pick the best hand.

Evaluated objects are compared and sorted by the rank of the hand.


List of objects to make the hand from. The method should be called after manual update to re-evaluate the updated hand.

Following attributes are available after evaluating the hand.


Readonly rank of the hand (0 = high card to 8 = straight flush)


Readonly list of cards which complete the rank.


Readonly list of extra cards which can break a tie.


Evaluate the rank of the hand.

Should be called either implicitly at start by leaving parameter evaluate True when creating the hand or explicitly by calling this method later, e.g. after changing the cards attribute manually.

Indices and tables

Table Of Contents

This Page