Skip to Content
FastAPI
book

FastAPI

by Bill Lubanovic
November 2023
Intermediate to advanced
277 pages
4h 55m
English
O'Reilly Media, Inc.
Content preview from FastAPI

Chapter 18. Games

Preview

Games cover a lot of ground, from simple text to multiplayer 3D extravaganzas. This chapter will demonstrate a simple game and how the web endpoint can interact with the user across multiple steps. This process is different from the familiar one-shot request-response web endpoints that you’ve seen so far.

Python Game Packages

If you really want to get into Python for games, here are some useful tools:

But I’m not going to use any of these in this chapter. The example code can get so large and complex that it overshadows the goal of this book: creating websites—APIs and traditional content—with FastAPI, as simply as possible.

Splitting Game Logic

There are so many ways to write a game. Who does what, and who keeps what where—the client or the server? The web is stateless, so each time the client calls the server, the server is a total amnesiac and swears it’s never seen this client before. So we need to keep state somewhere: data retained across game steps to thread them all together.

We could write a game completely in JavaScript on the client side, and keep all the state there. If you know JavaScript well, that’s a good solution, but if you don’t (a possibility, because you’re reading a Python book), let’s give Python something to do too.

At the other extreme, we could write a server-heavy application: generate some distinct id for this particular ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Building Micro-Frontends

Building Micro-Frontends

Luca Mezzalira
Practical MLOps

Practical MLOps

Noah Gift, Alfredo Deza
Learning Go

Learning Go

Jon Bodner
FastAPI Cookbook

FastAPI Cookbook

Giunio De Luca

Publisher Resources

ISBN: 9781098135492Errata Page