Skip to main content

playingcards.py

An Advanced and Customisable Python Playing Card Module that makes creating playing card games and running simulations general, simple and easy!

Features

  • Easy to use python interface
  • Easy to Understand, general, Class Objects
  • Card Comparisons

Installation

Requires Python 3.9 and above

You can install the module from PyPI or by using pip.

# Linux/MacOS
pip3 install playingcards1598

# Windows
pip install playingcards1598

How To Use

Quick Start

To quickly get started you can initiate a deck

from playingcards import Deck

deck = Deck()

Shuffle the deck using shuffle()

deck.shuffle()

Draw cards from this deck by using draw_top_n()

drawn_cards = deck.draw_top_n(5)  # Draws 5 cards

print(len(deck))  # Prints 47
print(len(drawn_cards))  # Prints 5

Return the deck to original form using reset()

deck.reset()
print(len(deck))  # Prints 52

Customization

Custom Cards

This module presents three class objects for creating custom cards: Rank and Suit for the building blocks, and Card for the construction.

You can construct custom classes as follows

rank = Rank('J', num_value=11)  # Creates a Jack rank
suit = Suit('s', pretty='♠')  # Creates a spade suit

card = Card(rank, suit)  # Creates the Jack of Hearts

A full deck of custom cards can be created by passing it during the Deck initiation.

custom_deck = Deck([card])  # A custom deck consisting of only the card the specified above

Alternatively, a custom deck can be instantiated using the from_ranks_suits() class method

big_red_deck = Deck.from_ranks_suits(
  [Rank(value, num) for rank, num in [('A', 14), ('K', 13), ('Q', 12), ('J', 11), ('T', 10)]],
  [Suit(suit, pretty) for suit, pretty in [('h', '♥'), ('d', '♦')]]
)

Card Collections

Deck is a subclass of CardCollection

Other CardCollection's are possible. For example, to create a Texas Holdem Poker hand (two cards), you could do the following

class TexasHand(CardCollection):
    def __init__(self, cards: list[Card]):
        super().__init__(cards, maximum = 2)

Class Arguments

  • Rank Arguments

    • value str - A string representation of the value of the rank
    • num_value int (optional) - A numerical value of the card, used in games that consist of ordering
  • Suit Arguments

    • value str - The desired value of the suit - s, h, c, d for a standard deck
    • pretty str (optional) - A prettier representation of the suit - ♠, ♥, ♣, ♦ for a standard deck
  • Card Arguments

    • rank Rank - The rank of the card
    • suit Suit - The suit of the card
  • Deck and CardCollection Arguments

    • cards list - A list of the cards in the collection
    • maximum int (optional) - The maximum number of cards in the collection

Release files for playingcards1598 1.3.5

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

Source distribution (sdist)

Source distribution for playingcards1598 1.3.5
File Size Uploaded
playingcards1598-1.3.5.tar.gz 7.6 kB Details

Release files / playingcards1598-1.3.5.tar.gz

Download URL playingcards1598-1.3.5.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2e219ac0ac54155a9a3e86cbacd5201ccdb858b4d55102e64049a3a93113d2e2
BLAKE2b-256 checksum
How to use checksums
f1f6b5829b7bba924833aacbc5a7c1a9b0b3fd5685b38a247932551fc60ee02e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release history Release notifications | RSS feed

This release

1.3.5 This release

1 release file

1.2.5

1 release file

1.2.4

1 release file

1.2.3

1 release file

1.2.2

1 release file

1.2.1

1 release file

1.1.8

1 release file

1.1.7

1 release file

1.1.6

1 release file

1.1.5

1 release file

1.1.4

1 release file

1.1.3

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.0.10

1 release file

1.0.9

1 release file

1.0.8

1 release file

1.0.7

1 release file

1.0.6

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

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