Python-powered Chat Apps with Twilio and SendGrid Transcripts
Chapter: Appendix: Using SQLAlchemy
Lecture: Creating the basic insert script

Login or purchase this course to watch this video and the rest of the course contents.
0:00 In this chapter, we're going to look at actually using SQLAlchemy. Previously we had modeled all of our data but we didn't do anything with it.
0:09 We didn't do any insert queries, updates none of that. That's what we're going to do now. And to get started
0:14 we're just going to jump right into writing some code. And so I just want to point out we are now in Chapter 10
0:19 Using SQLAlchemy, working on the final bits here. So let's switch over to PyCharm grab our new chapter and get going.
0:27 This is the code from before, just carrying on. And what we're going to do is we're going to actually have over here a new directory called bin.
0:36 Now, this is just a convention that I use. I've seen it in other places as well and this bin folder comes along with our website
0:42 for little admin tasks and scripts that we need to run and so on. It's not directly involved in running the site but more like maintaining the site.
0:50 So, for example we're going to do some importing of data. And to do so, we're just going to write some scripts here. They don't actually run normally
0:58 but they're going to run here. Let's go over and add a Python file called basic_inserts.py.
1:04 We're going to take two passes at showing how to insert data. First, we're going to write some example data just standard make-up stuff.
1:13 And then I'm going to show you I've actually got a hold of the real PyPI data for the top 100 packages using their API and we're going to insert that.
1:22 Turned out that's super, super tricky. There's lots of little nuances and typecasting and all that kind of stuff we have to do
1:29 to make it work just right. We're not going to do that first we're going to do like a simple example and then I'll show you the program
1:34 that'll actually generate our real database. So, here it is. We already have our database right here and if we look at it
1:45 we'll see that we have our packages and releases put together. And, of course, there are the interesting ones.
1:50 Actually, I'll go over here and show you a little more. Show you a visualization pop-up. It's kind of a cool feature of PyCharm.
1:58 So we have our packages and this relationship between the releases. That's probably the most interesting part of our database.
2:04 We didn't actually set up save, like the maintainers and what not here. This should maybe have, like some relationships and so on
2:12 but we didn't set up all the relationships for our data model, just the really important ones. So, we're going to focus on just those two tables.


Talk Python's Mastodon Michael Kennedy's Mastodon