Modern APIs with FastAPI and Python Transcripts
Chapter: Building our first API
Lecture: Project setup

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now for us to build our application,
0:01 we need to create a new web project.
0:04 Now, almost every web project that I know of depends on external libraries
0:09 and anytime you have a python library or python application
0:12 that depends on external libraries, you're gonna want to start by creating a virtual environment.
0:16 And of course, this is no different.
0:18 So that's what we're gonna do.
0:20 here we have the demos, and right now we only have chapter three.
0:22 Of course, all the chapters will be here by the time you're watching the course.
0:25 Let's go over here, this will let me just pop open a terminal right
0:29 there. And what we're gonna do is we're gonna create a virtual environment.
0:33 So I'm gonna say "python3
0:35 -m venv venv"
0:39 and now we're gonna activate it.
0:40 So on Windows, you would activate it just by saying "venv/scripts/
0:46 activate" But on Mac and Linux,
0:49 you say dot, to apply it to this shell,
0:52 then "venv/bin"
0:54 why is it bin not scripts? Take that up with someone else.
0:57 I have no idea. But we're gonna activate it like this and you'll see our
0:59 prompt change either way, where it says now you're in this virtual environment.
1:03 We can ask things like "which python"?
1:06 Yep, it is the one that we're working with.
1:08 Another thing we wanna look at is by default,
1:11 whenever we create a new virtual environment,
1:13 there's a 95% chance that pip itself will be out of date.
1:17 So let's just go ahead and upgrade that real quick as well.
1:20 I'll just go and do these things next time and not run you through it,
1:22 but first time through, I want to talk about it. Alright,
1:27 everything looks like it is good and we have our virtual environment.
1:31 Let's go ahead and just come over here and open this in PyCharm.
1:34 Now on Mac OS, you could drag it onto the icon. on the other
1:37 OS's, you just go to PyCharm,
1:39 say "file, open directory" or visual studo code, and open that directory as well. Alright,
1:45 so notice down here, it says "no interpreter".
1:47 There's a chance that it might pick the right one.
1:50 Let's go and see which one it's after.
1:51 This seems to always change, it's super frustrating, and the way it works, like Sometimes it works
1:56 and finds the local one we created,
1:58 sometimes it doesn't. This time it didn't.
2:00 So we're gonna say go to our home directory,
2:02 go to venv, bin or scripts,
2:04 pick Python. Okay, now it looks like everything is working.
2:10 It's gotta read through Python real quick just to make sure it understands all the types and
2:14 then we'll be ready to get going.
2:16 Next up, let's go and create a "main.py"
2:20 That's pretty common in FastAPI to have a main that we're going to
2:22 run, and I'm just going to right click and say "run" to make sure everything's working.
2:26 Okay, the last thing we need to do is we're gonna need to be
2:29 able to use FastAPI.
2:32 And if I go and run this again,
2:34 then it's not so happy about it, right.
2:36 The last thing we have to do is install FastAPI, and
2:39 we're going to keep track of our dependencies by having a "requirements.txt", and in
2:45 here, we're gonna put "fastapi", for now,
2:49 we're gonna have a bunch more later,
2:51 and of course it's suggesting it could install it for us,
2:54 but I'm just going to go to the terminal and show you what we would
2:57 run more generally would say "pip install -r requirements.txt" with the virtual environment active,
3:05 we get all the dependencies of FastAPI at this time. Alright,
3:10 It looks like everything is good.
3:11 I think it believes it's misspelled,
3:13 which is unfortunate, but you could tell it to stop showing you that.
3:16 And let's just do a print,
3:18 "hello fast api" and run this.
3:22 Alright, Perfect. So it looks like we've got our system set up,
3:25 ready to run Python or running Python 3.9 at the moment.
3:29 If you're unsure which version you got,
3:31 you can come down here. We have 3.9.0 at the moment,
3:35 but again, anything from 3.6 or beyond should be fine for what we're doing and
3:40 were able to install and import
3:43 FastAPI. So I think our app is ready to, well, begin writing it actually.