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