1. Start with the Parsing the query string in a request recipe as a template for a Flask application. We'll be changing the view functions in that example:
        from flask import Flask, jsonify, request, abort, make_response 
        from http import HTTPStatus 
        dealer = Flask('dealer') 
  1. Import any additional modules. In this case, we'll use the uuid module to create a unique key for a shuffled deck:
import uuid 

We'll also use the Werkzeug BadRequest response. This allows us to provide a detailed error message. This is a little nicer than using abort(400) for an erroneous request:

        from werkzeug.exceptions import BadRequest 
  1. Define the global state. This includes the collection of decks. It also includes the random number generator. For testing ...

Get Modern Python Cookbook now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.