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

Talk Python's Mastodon Michael Kennedy's Mastodon