Book Image

Learn Python Programming, 3rd edition - Third Edition

By : Fabrizio Romano, Heinrich Kruger
5 (1)
Book Image

Learn Python Programming, 3rd edition - Third Edition

5 (1)
By: Fabrizio Romano, Heinrich Kruger

Overview of this book

Learn Python Programming, Third Edition is both a theoretical and practical introduction to Python, an extremely flexible and powerful programming language that can be applied to many disciplines. This book will make learning Python easy and give you a thorough understanding of the language. You'll learn how to write programs, build modern APIs, and work with data by using renowned Python data science libraries. This revised edition covers the latest updates on API management, packaging applications, and testing. There is also broader coverage of context managers and an updated data science chapter. The book empowers you to take ownership of writing your software and become independent in fetching the resources you need. You will have a clear idea of where to go and how to build on what you have learned from the book. Through examples, the book explores a wide range of applications and concludes by building real-world Python projects based on the concepts you have learned.
Table of Contents (18 chapters)
16
Other Books You May Enjoy
17
Index

The railway API

Now that we have a working knowledge of what an API is, let's turn to something more concrete.

Before we show you the code, allow us to stress that this code is not production-ready, as that would have been too long and needlessly complex for a book's chapter. However, this code does its job and does it well, and it will allow you to learn quite a lot if you decide to study it, evolve it, and improve it. We will leave suggestions on how to do so at the end of this chapter.

We have a database with some entities that model a railway. We want to allow an external system to perform CRUD operations on the database, so we are going to write an API to serve as the interface to it.

CRUD stands for Create, Read, Update, and Delete. These are the four basic database operations. Many HTTP services also model CRUD operations through REST or REST-like APIs.

Let's start by taking a look at the project files, so you will have an idea of...