Deck of Cards

Fun API · Works globally · Virtual card decks · Stateful API sessions

TL;DR

The Deck of Cards API lets you create fully functional virtual playing card decks that persist across API calls. You can shuffle one or more decks, draw cards from the top, reshuffle remaining cards, and organize cards into named piles. Each deck is given a unique ID that persists until all cards are drawn or the deck is discarded. It is the perfect backend for browser-based card games, teaching tools, or any application needing a standard 52-card deck.

Quick start: https://deckofcardsapi.com/api/deck/new/shuffle/?deck_count=1

No API key needed — just make a request!

How to Use This API

1. Create and Shuffle a New Deck

https://deckofcardsapi.com/api/deck/new/shuffle/?deck_count=1

2. Draw Cards

Use the deck_id from the response to draw cards:

https://deckofcardsapi.com/api/deck/{deck_id}/draw/?count=2

3. Add to Pile

Organize drawn cards into named piles (like "player1" or "discard"):

https://deckofcardsapi.com/api/deck/{deck_id}/pile/player1/add/?cards=AS,2S

4. JavaScript — Deal Two Poker Hands

// Create deck
fetch('https://deckofcardsapi.com/api/deck/new/shuffle/?deck_count=1')
  .then(r => r.json())
  .then(deck => {
    const id = deck.deck_id;
    // Draw 10 cards for two players
    return fetch(`https://deckofcardsapi.com/api/deck/${id}/draw/?count=10`);
  })
  .then(r => r.json())
  .then(hand => {
    hand.cards.forEach(c => console.log(c.value + ' of ' + c.suit));
  });

5. Python — Blackjack Simulation

import requests

# New deck
resp = requests.get('https://deckofcardsapi.com/api/deck/new/shuffle/', params={'deck_count': 1})
deck_id = resp.json()['deck_id']

# Deal two cards
draw = requests.get(f'https://deckofcardsapi.com/api/deck/{deck_id}/draw/', params={'count': 2})
for card in draw.json()['cards']:
    print(f"{card['value']} of {card['suit']}")
Try it: https://deckofcardsapi.com/api/deck/new/shuffle/?deck_count=1

API Details

API URL
https://deckofcardsapi.com/api/deck
Documentation
deckofcardsapi.com
Category
Fun
Authentication
Not Required
Geographic Coverage
Global

Frequently Asked Questions

How does deck state work?
Each deck gets a unique deck_id. The API remembers which cards have been drawn until the deck runs out. Cards cannot be returned to the deck.
Can I use multiple decks?
Yes, set deck_count to any number when creating the deck. Great for games like blackjack that often use 6-deck shoes.
What card data is returned?
Each card includes code (e.g., "AS", "KH"), image (URL to PNG), value, suit, and card images for both standard and SVG formats.
What are piles used for?
Piles let you organize cards into groups like player hands, discard piles, or community cards. Pile endpoints let you list, draw from, or shuffle piles.
How long does a deck persist?
Decks persist on the server for a limited time. Create a new deck when you start a game session rather than reusing old deck IDs.
Can I create a partial deck?
Yes, use /api/deck/new/shuffle/?cards=AS,2S,3S to create a deck with only specific cards.

What You Can Build