#100DaysOfWeb in Python Transcripts
Chapter: Days 9-12: FastAPI
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, we need to create a new web project. Now almost every web project that I know of depends on external libraries.
0:10
And anytime you have a Python library or Python application that depends on external libraries,
0:15
you're going to want to start by creating a virtual environment. And of course, this is no different. So that's what we're going to do.
0:20
Here we have the demos. And right now we only have chapter three, of course, all the chapters will be here by the time you're watching the course.
0:27
Let's go over here. We just pop open a terminal right there. And what we're going to do is we're going to create a virtual environment.
0:34
So we're going to say Python 3-m venv venv. And now we're going to activate it.
0:42
So on Windows, you would activate it just by saying venv scripts slash activate.
0:49
But on Mac and Linux, you say dot to apply it to this shell, then venv bin. Why is it been in scripts? Pick that up with someone else. I have no idea.
0:59
But we're going to activate it like this. And you'll see our prompt change either way where it says now you're in this virtual environment,
1:04
we can ask things like, which Python? Yep, it is the one that we're working with.
1:10
Another thing we want to look at is by default, whenever we create a new virtual environment, there's a 95% chance that pip itself will be out of date.
1:19
So let's just go ahead and upgrade that real quick as well. I'll just go ahead and do these things next time and not run you through it.
1:24
But first time through, I want to talk about it. All right, everything looks like it is good. And we have our virtual environment.
1:32
Let's go ahead and just come over here and open this in PyCharm. Now on macOS, you can drag it onto the icon on the other S's, you just go to PyCharm,
1:40
say file, open directory, or Visual Studio Code, and open that directory as well.
1:45
Alright, so notice down here, it says no interpreter, there's a chance that it might pick the right one. Let's go and see which one is after it.
1:53
It seems to always change, it's super frustrating. And the way it works, like sometimes it works and finds the local one we created, sometimes
2:00
it doesn't. This time it didn't. So we're going to say go to our home directory, go to vnv, bin our scripts, pick Python.
2:08
Okay, now it looks like everything's working. It's got a read through Python real quick just to make sure it understands all the types.
2:15
And then we'll be ready to get going. Next up, let's go and create a main.py. That's pretty common in FastAPI to have a main that we're going to run.
2:25
And I'm just going to right click and say run to make sure everything's working.
2:28
Okay, the last thing we need to do is we're going to need to be able to use FastAPI. And if I go and run this again, it's not so happy about it.
2:37
The last thing we have to do is install FastAPI. And we're going to keep track of our dependencies by having a requirements.txt.
2:46
And in here, we're going to put FastAPI. For now, we're going to have a bunch more later. And of course, it's suggesting it could install it for us.
2:55
But I'm just going to go to the terminal and show you what we would run.
2:59
More generally, we'd say pip install -r requirement with the virtual environment active. We get all the dependencies of FastAPI at this time.
3:10
All right, it looks like everything's good. I think it believes it's misspelled, which is unfortunate, but you can tell it to stop showing you that.
3:18
And let's just do a print, ""Hello, FastAPI,"" and run this. All right, perfect.
3:24
So it looks like we've got our system set up, ready to run Python or running Python 3.9 at the moment.
3:30
If you're unsure which version you got, you can come down here. We have 3.9.0 at the moment.
3:36
But again, anything from 3.6 or beyond should be fine for what we're doing. And we're able to install and import FastAPI.
3:45
So I think our app is ready to, well, begin writing it actually.