Full Web Apps with FastAPI Transcripts
Chapter: Creating our first FastAPI *site*
Lecture: Creating the Python project

Login or purchase this course to watch this video and the rest of the course contents.
0:00 it's time to start writing some Python code and creating our FastAPI not
0:06 API, but web application. Our Python project for a web application.
0:10 Here we are in our GitHub repository and you can see we have a bunch
0:14 of empty chapters of what I think the structure is going to be.
0:17 And we're going to start by creating our project here,
0:21 evolve it. And then when we're ready to move on to templates for chapter four
0:24 make a copy from what we did here,
0:28 over to here. That way you could always just jump in at any given section throughout
0:32 the course in case you didn't follow along exactly,
0:34 or you just want to quickly jump into a section and see what it was like
0:37 there. We want to go over here,
0:40 and we're going to create that project.
0:42 Now we're gonna open this in PyCharm,
0:44 but also show you how to get started before, just in a terminal.
0:49 So I have this cool little extension called Go2Shell.
0:53 That'll let us jump in here.
0:54 But you could obviously open a terminal or command prompt and just cd over into this
0:58 directory. So if we look here,
1:01 there's just this placeholder text so GitHub would create the or git would create the
1:05 project structure. Now what we would need to do there's a couple of things that make
1:09 up a FastAPI project. We're going to start by just having a main.
1:14 So what we're gonna do is We're going to create a main.py,
1:18 file. We're also going to need some requirements. And the easiest,
1:25 most common way to do that is to use a requirements.txt. Yeah,
1:29 we could use poetry or pipenv or whatever,
1:31 but I'm still a fan of just the requirements.
1:35 We're going to create that as well,
1:37 and we'll put in things like we require FastAPI,
1:39 and we require uvicorn to run it and so on.
1:42 And then I wanna have a virtual environment.
1:44 So I'm gonna come over here and say python,
1:46 you may need to type python3, depending which version you got.
1:50 -m venv,
1:52 venv. We're not gonna do this from scratch for everyone.
1:57 I'm just gonna walk you through it once and now we have our virtual environment.
2:01 But if we ask which python.
2:03 It's still we ask which python3
2:05 It's still the system global one. On Windows,
2:10 which is not a command, but where is a command that will tell you basically
2:13 the same thing. So we need to make sure we activated. So on Mac OS
2:18 or Linux we say dot or source.
2:20 venv/bin/activate like that and notice our prompt changes.
2:25 If this was Windows, we would just venv/scripts/activate.bat
2:30 like so you could drop the bat that would still run.
2:33 But over here, I got to say this. Now,
2:36 if we ask which python it's this one here all right?
2:41 Any time you work with virtual environment,
2:44 it's almost always got an out of date pip.
2:46 So let's fix that real quick.
2:48 pip install. Sorry. -u for upgrade pip and setuptools.
2:56 Now we do a pip list.
2:58 You see, we've got the latest version.
2:59 Now that we have our virtual environment up and running,
3:03 let's go ahead and open this in PyCharm, we're no longer going to need this
3:06 on Mac OS you can drag the folder onto PyCharm and it'll open. On
3:11 the other operating systems, you have to go file open directory.
3:15 Same basic idea. You can see PyCharm's found our virtual environment.
3:19 Surprisingly, this sometimes works, sometimes doesn't.
3:22 So you can always go add interpreter and pick the existing one that usually finds it
3:26 or if you have to, you can browse to it as well,
3:28 but it looks like we're good over here.
3:30 This are red because in GitHub,
3:32 they're not yet staged. So our project is over here.
3:37 And let's just do a quick print hello,
3:41 web world just to make sure that we can run everything and right click,
3:47 say run. Perfect. It looks like everything is running over here just fine
3:51 So we've got our project created.
3:54 Obviously, it's not a FastAPI project just yet,
3:56 but this is the process that we're gonna go through for each one.
4:00 I won't walk you through it again.
4:01 Well, I'm just gonna do this and say,
4:03 Hey, I did this set up to get our project running and start with the existing code at each chapter