Modern APIs with FastAPI and Python Transcripts
Chapter: Building a realistic API
Lecture: Creating the weather project
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
Well, we're into a new part of the course, so we're going to go to a new part of our GitHub repo and come over here and just set it up from scratch.
0:09
We already did this over in first API, remember? We created the virtual environment,
0:14
the requirements and so on. But let's just run through it one more time real quick without nearly as much explanation.
0:20
We're going to start by creating a virtual environment with Python 3. Then we're gonna activate. And of course, pip is always out of date,
0:30
so pip, re-install, upgrade pip, and might as well do setuptools too. Excellent. Now let's throw this over in to PyCharm.
0:45
Make sure we've got the right virtual environment, which lately is never the case. That's super frustrating. PyCharm used to do this automatically,
0:52
and now not so much, but we can just go find it over here. We'll add our "main.py", and let's go ahead and do our "requirements.txt", and over here
1:06
we'll have FastAPI, uvicorn. We're also gonna need some other libraries.
1:13
We're gonna need httpx to consume some external library, and those three should be good. Let's just go ahead and hit
1:19
install, let PyCharm do the magic, "pip install -r requirements.txt" If not, remember on the command line, and let's get our "hello world"
1:29
thing going. So we'll import FastAPI and we'll import uvicorn, and we'll say "api = fastapi.FastAPI(), Hello Weather app" and that's all we got to do
1:53
for this. And we'll do our little main magic, we'll say, come down here and we'll do a uvicorn, run, API, port,
2:02
just be explicit, although it does default to that one, and that's it. Let's run it, make sure it works. Oh, yeah, Looks like it's working.
2:13
Click on it and beautiful. Hello, weather app. Again, this is actual JSON. Well, it says the content type is JSON,
2:21
even though it's well, it's just plain text, but we're not gonna worry about that.
2:24
That's not where our app is staying. We got it up and running, got our little "hello weather app". Got the whole project set up and ready to go.
2:31
Well, now it's time to start adding our homepage and our API featurs to it.