From the course: Advanced Python: Practical Database Examples

Unlock the full course today

Join today to access over 24,500 courses taught by industry experts.

Define a database schema

Define a database schema

- [Instructor] The purpose of our API is to host book data and allow different clients to access it. The book data will live in a database. Before we can store it there we need to define the schema for what we will store about a book and how we will store it. We'll be using SQLAlchemy to create our schema and access the data in our database. Let's install it in its dependency MySQL Connector. We'll be doing this in a virtual environment so let's activate it. And we'll install MySQL Connector. We'll also install SQLAlchemy. Perfect. Now we can look at some SQLAlchemy code that defines the schema. If you're using the exercise files these are located within the books API folder in a file called database.py. SQLAlchemy is a module in Python that helps you communicate with your database. Instead of writing raw SQL statements you can declare the interactions of your application in the database in a more Pythonic way.…

Contents