๐ Lunch & Learn: Build and Deploy Python API Workshop
Key Takeaways
This video demonstrates building and deploying a Python API using Flask, with a focus on API design, deployment, and integration with services like Airtable and Render.com. It also showcases the use of Chat GPT for generating code snippets and live debugging.
Full Transcript
cool and we are live I think yes and we are live Hello friends how's it going oops I need to mute myself how's it going hi Tina hello my chat window seems to be very small right now let me try no what's up everyone this is Keith and we will say where are you guys all coming in from let us know where you guys coming in from yeah we're super excited to do this wall I got to thank Keith again for doing this and you're going to be building and deploying a full python API doing this Workshop all right well maybe I'll give a brief introduction for Keith um actually Keith do you want to give a brief introduction of yourself sure I will uh share my screen too I'll I'll throw a little slideshow up as we go uh as people kind of trickle in too but excited for this this is going to be fun give me one second hello hey upas hey iers hello n hi that won my dority so glad to catch this life right oh I'm glad that you're here from AWS Cloud engineer to to whom hi Keith says Alex what's UPA from New York yeah where's the where's the farthest uh farthest viewer from so far and just for context I'm I'm in the Boston area so I'm East Coast United States I'm in Austin right now which is is that in the middle I don't even know where that is you're pretty Central okay yes well it is like CST so you know Central yeah yeah it does kind of throw me off that it's only one hour behind uh uh East Coast I kind of always expect it to be two hours but uh it's mountain time yeah two hours I see Morocco in Italy Morocco New Zealand Spokane Washington Nebraska India India thanks for making it I know it's kind of late in the Oceana and Asia regions so appreciate it it Germany Poland Germany one of my favorite countries first time watching one of these but transition from systems Administration to cyber security and want to get some python learnings originally from Chicago but now in LV hello hey Bob Canada did you hear Roman far did you hear Roman no I'm not sure what that means but we are around 2 minutes in Louisiana nice I love Louisiana one of my favorite places too Thailand okay I figured um Keith do you want to just give like a brief intro about yourself like super brief yep and then we can get started awesome yeah definitely uh so what's up everyone super excited to be here my name is Keith gy um little bit about me uh I had my bachelor's and Ms in computer science from MIT uh always been a math nerd uh studied computer science at MIT and kind of Applied that mathematical knowledge uh CS is a great way to do that so same type of logical thinking a lot of fun um I'm currently a founding engineer at a company called crater AI we're super small startup five person but hopefully some exciting things coming uh our way um with what we're building right now so more updates on that front but I think that some people here might know me from uh the educational YouTube channel that I have I make a lot of python focused videos so I guess my Niche is kind of python meets data science so a lot of you know pandas videos a lot of like numpy uh real world projects so that's kind of uh you know where I live at on my channel feel free to check it out out um and then I'm also very professional as you can tell with making uh slideshows so uh wow cute is this on Photoshop uh yeah this is Photoshop just a quick quick uh use the object detection tool and just threw some uh pictures in here but uh little about me but agenda for today uh we have an hour so hopefully we can get through everything if we don't get through everything I would say feel free to leave comments like on this live stream and I'll do my best over the next like week or two to just see if there's um you know any comments that I can answer then I also guess for context too I'm going to work on kind of putting what we're going through today into a tutorial on my own channel so I might try to address some questions that maybe we can't answer during this uh session um you know in a couple weeks when I make my own uh channels tutorial but we'll start with a quick little overview of apis uh probably be a refresher for a lot of people but I think it's just good to set the kind of scene of you know why we're even talking about apis to begin with then we'll spend the bulk of this session um building and deploying an API with python and flask and a couple other cool libraries to like just make it a little bit more full scale full picture then I'll try to leave like five to 10 minutes at the end for some Q&A awesome one thing sorry to intro Keith no you're good anybody who is wants once they get ready and then code along download the starter code it's in the pin comments uh so it's on GitHub you can clone it or download it and then you can follow along as Keith is coding as well so yeah please back to you awesome thank you that's good good call out um and if yeah if people have any issues like I would say if you run into any issues as you're trying to follow along don't worry too much about it I would say just follow along and then the video will be here I'll try to answer some questions after the session's over via the comments but all right let's just talk about real quick kind of a quick overview of like why we're using apis here I think just set the scene so I'm going to you know paint the picture a little bit uh so here I am backend engineer and we're going to be working on a python or an app that basically lets us review books and rate books and right now we have some python code that lets us do that um but really it's not super accessible to others you know people don't want to have to run python code especially if you're like trying to deploy this app for your mom to use or something like she's not going to be able to she she might not you know know how to code and uh it might be a little tricky for her to run this python code to rate books and and see all your rating so you know back in engineering side take care of that and then on the other side you know we want to build an application to rate and you know save our ratings of books so we have a front-end engineer working here uh geith c um and geith is responsible for building a mobile interface for this book rating application and so really like the reason that I like to spin up apis as we're going to kind of go through in this um session like it's just a very quick and efficient way and ultimately like I have no expertise in frontend engineering unlike geith here uh and when I want to write a bunch of python code and actually build an application build a you know web app Etc usually it's important for me to have all that python code encapsulated in an API and then bring in a front-end expert to um you know help make this actually a real thing so the basic flow kind of is uh I can focus you know over here on the python code on the server side the back end and you know might have a frontend engineer working over here and as long as you can provide a little bit of an API to access your python code on the back end and kind of send data back for them to populate on the front end like you're in a very good spot makes it way easier to work with teammates so like being able to deploy these quickly is like super uh super helpful for deploying applications uh quickly um and I'll pause there any questions that I should address in the chat is anybody having any trouble opening um um the starter code now is the time to ask um starter code it looks like we're okay hello everyone from Washington State hello I think we should be okay we will count to five five all right we we'll keep watching it too you'll okay yeah I I'll be here if you have any trouble just write something in the chat we'll get back to you yeah um so like ideally what we're trying to build here is like this kind string where we have our python code running and you can just uh on the front end or you know anywhere else you could run a command hit this URL and you know get a rating basically get a um a uh you know get a request and have some python code kind of run behind the scenes to actually do that so that's what we're trying to aim for here having that you know URL that we can access uh just a little bit of extra context on apis these are I would say the four main commands that you'll probably see um within rest API world you might also see delete um but there's a little bit of information on them I'm not going to spend too much time on it uh but we'll be kind of focusing on get getting and posting data um in this tutorial and then finally uh just want to mention like api's broader scope like any big platform that you want to be able to access programmatically they usually offer apis so just listing some here you know if you want to do something in your application that's Financial payments related you might tap into Stripes API if you wanted to like automatically post YouTube videos or automatically pull your YouTube analytics data uh you might use the YouTube API uh twilio is a cool API if you want to like program um like a phone number to be able to like text and you know receive text messages and text people back maybe you put like a little bot up and can respond via SMS you could use twilio to programmatically do calls and messaging and then I think most people here are probably pretty familiar with openi at this point but I think it's really fun playing around with chat GPT on you know uh chat or chat. open.com but if you ever wanted to build your own custom program with openai like you're going to want to use the openai API so just some examples here but I think with that being said let's get into the meat of the uh session here and actually go ahead and start building and deploying an API with python and flask so this is pinned in the YouTube chat um it's on a a specific Branch uh um hopefully hopefully you can see that yeah it's on this Branch um lunch and learn but I'm going to go ahead and navigate there and we're going to start actually getting this code set up and uh working towards uh building this API so just for anybody that's not familiar with apis or rest apis it's generally just a a way for software to interact with each other on a very large basis so if other people build a software you want to use that software instead of writing everything yourself you can tap into that and rest API is a certain framework that is very very commonly used um in API world sorry Keith just to explain a little bit the context is helpful so thank you for jumping in okay let me share my screen again all right so everyone hopefully should be able to see um this uh GitHub link so again this is a pinned comment in the chat um python API example and then we're going to specifically be working off of this lunch and learn Branch uh just because I probably will tweak around with the master Branch here so the starter code will always be living on lunch and learn here um it's not too much code here to be to work with so if you really needed to you could kind of like you know copy and paste all these individual files uh but I also put some setup instructions um over here in the read me so I'm going to slowly start working through this if you don't understand all of the logistics of like cloning with GitHub and all that don't worry too too much about that know that the code will be here for you and I just kind of want to start um working towards what we can do uh on the API side so I'm going to go ahead and download this code I know that this terminal is really really small right now so let's see if I can uh oh no make it a bit bigger okay so I'm going to go ahead and make a directory I'll just call it lunch learn go into my lunch learn ah it went dark in my office we did it actually yeah we're good we're good we're good uh okay so I I'm it doesn't matter where you clone this code but I have this little lunch learn directory that I'll just put it in and then we're going to go ahead and with this GitHub code uh I would recommend forking this repo first just so you can basically push all this code locally it gets a little bit confusing for me to do that on my own repo so I'm going to just go ahead and um clone it and I'm specifically cloning this lunch and learn Branch here um Minor Detail doesn't matter too too much I think if you cloned the master Branch you'd still be in a good spot you just might have some extra code okay and now once you've done that you should have all this code um within this python API example folder because the terminal is not the best place to watch me write code I'm going to open up visual studio to um actually start working on this I just actually might want to I want to make sure that I'm all the way in that python API example full fer so I'm going to just do this one more time like there we go right so if you've been able to clone it and really honestly don't worry if like you're a little bit behind and you don't have everything here the code will still be there if you check back on this video in a week um but I think the basic thing that I want to start showing is with some very simple um template code we can already basically have like an API spun up so we're going to do a couple steps so in the GitHub readme uh we want to navigate into this directory and we're there in Visual Studio code and then we want to make sure that we have all of the requirements um for this repo so common practice if you're ever working on a python based repository it's good to have a requirements.txt file what this file does for you is that you can put all of your dependency libraries uh in the requirements.txt T file and so what we see here we have flas flaser flask restful Pi air table and gunicorn um and the nice thing about this is we have all of these libraries here and if I go ahead and run hopefully you can all see this pip install dasr so the- R is specifying we're going to be installing python libraries from a requirements.txt file F requirements.txt and run that uh it should download all of your um uh libraries I think depending on where you're installing python note that sometimes it's pip sometimes it's pip 3 so for me it's actually going to be pip 3 install requirements.txt if I close this you can see that a little bit more clearly go ahead and run this and you'll see that I have all those um reposit or those libraries already installed but that should set you all up to be able to kind of run this code um I'll pause there real quick is there any questions that I probably should address in the comments right now um Tina or we good right now nope we are good Okay so we've now installed so going back to the GitHub readme we've installed all of our python Library and now we're just going to start with template code and sometimes like sometimes you be like oh hey like why aren't we starting from complete scratch like why aren't we starting from a total blank slate and I would say with something like this it's like better to just have like a very rough template code in front of you run that and just make changes as you need because this is the type of thing where is like I need the template code to know where to kind of start building off of it's kind of hard to remember how to do this exactly totally from scratch so I like having like templat code in this type of scenario um so I'm going to go to app.py and if you want to just see what's in there so far we really have a very very basic function um I'll I'll zoom in and zoom out on this code so you can hopefully see it all but I want to zoom out just so you can kind of see the full scale real quick but basically we're using this Library called flaser and so just to give some context on these libraries here flask is a very common python library for building server servers um it's very it's pretty lightweight it's lighter weight than I you know say d Jango uh you can spin up something quickly um so flask is a good option for apis for that reason um flask restful gives us an additional resources to just uh play with the doc strings and have a certain syntax that we can ultimately make documentation for these endpoints with uh and then flaser is pretty cool it lets us basically package up these dock strings that will kind of walk through down here into a nice API call and what's really helpful about this and you'll see it in just a second but um Swagger is a very common kind of um way to document your API code uh the Swagger spec I think was what it used to be called and now they've kind of moved to the open a open API like spec definition of like defining apis but basically it lets us have nice um interactive documentation that we can generate um as part of our project so basically this is a good template to start off of and what we'll see in a second is kind of how this all fits together so I'm going to go ahead and open a terminal and if we look at our F folder structure there's this app.py that's what we're going to run here I do Python 3 app.py and we see we have this little server running so just to kind of give you some context on how this is all packaged together down here we're running our little app and all the initialization is just like through these lines here and we have one single API call here and I'm going to break this down all in a second So within that terminal window if I open that back up um we see that it's running on this location this is a local endpoint question for you Keith yep are there any equivalent Swagger for Jango uh I'm sure there's something that you can define an API with d Jango off the top of my head I'm not familiar um but I'm sure that if you look up Swagger for jeno I'm guessing you'll probably find something okay so I went to that URL it pointed to me when I was running the app and it seems like a very scary thing to have here like not found like uh the nice thing though is like at least it's telling us not found um but within here the really small text on your screen probably if I just add a slash API docs to the end of this um with that little bit of template code that we have we already have this like nice little like UI um adhering to the Swagger spec um that has one single method in it uh um it has this get uppercase method and in the world of API calls a get request to just uppercase text is probably never needed but it's a cool little demo to just show like with this littleit bit of code that we have what we already can start doing um so locally we can be in this little interactive environment and I could just do something like hello world I could run this code and as we see we get back hello world in all caps very very basic U API request but we see kind of the request URL that is being passed here um and what's nice about this is this still might seem kind of like foreign territory but what's really nice as we're going to work towards in the session is that it's pretty easy if you said like you're a backend and engineer and you're trying to give a frontend engineer some API calls that they can hit to access all of your code having a little um you know set of documentation on a web page like this makes it super easy to play around with things test things like it gives you like how you can you know do a curl command to hit that endpoint it tells you what the endpoint is that you can run a local request at uh to hit that endpoint uh so you know very nice little details here I think the one thing I will mention though is right now this endpoint if you guys try to hit this this is very much just referring to my local machine uh it's not going to yet be like publicly accessible but we'll get towards that um as we go in the video um all right Tina I hear that you've unmuted yourself I don't know if there's a question that I'm about to answer but oh you can you can hear me unmuting myself I guess I can yeah that's a good way to like I was getting ready for a question from the audience I'm not good at multitasking so uh I apologize if people have been asking uh a bunch of uh questions throughout n no we're actually good so one question from Yash can we can also do this with streamlet to make our website um I mean streamlet I feel like has so many other great features and purposes I don't know if I would necessarily like use streamlet to set up like end points to run like an API but like you can very easily uh host streamlet applications that anyone could access to do all sorts of other things I feel like I often use streamlet more for data sciency like quick prototypes versus like a uh API that you know other people on my team need to access so uh what I'm going to show with deploying this flas cap will be probably very relevant to streamlet Applications but I wouldn't probably build my apis using streamlet I would probably use a more proven tool for this specific purpose uh in in flask cool thank you all right so we're at a good little spot here there's a you know a few different steps we need we need to make to actually make this a more robust API and actually do something meaningful with this um and actually deploy it but I think that this is a good spot to just maybe like um ask some people viewing what what is an interesting like little API endpoint that we could add so I want to make the the the um scope of this a little bit refined like let's have some sort of API um end point that does something with a string uh so you know it could maybe duplicate a string a certain number of times like give throw out some ideas maybe in the comments real quick on like different things we could do with string manipulation and we'll spin up a little API uh to to to do that we'll see if this this uh if we get anything from the the comments here but I'd be curious just to hear some people's thoughts on a little API endpoint we could do uh similar to like upper casing things but I just want to change up the parameters of bit so let's try to make it a little bit more complex than upper casing oh I just clicked again um I think it also might be helpful Keith if you don't mind explaining the full process so say you have this API here it does something and then you have that endpoint and then how after we obviously need to deploy it how would that be accessed from yeah somebody else yeah know that's a great great question I definitely will show it full scale I could just try it real quick now with my local um instance up I just don't know if it will work properly so we're going to do a live little demo while we're doing that um please in the comments write down what kind of function should we do something simple that we can do uh within the API okay upper casing things with strings splitting strings pending things to Strings just giving some random ideas over here write in the comments write in the chat what you think we can do thank you I hope that's helpful for anybody who is curious as to how that would work I understand uh like when you're first looking at something like a rest API like this I get that it could be a little bit confusing like seeing what's curl you know like how do things how is it actually being exposed so uh I think this would be really helpful so before deploying it just to like showcase like oh this is the full flow you're building this thing that does something and then how do you actually access the thing that's being built definitely okay so I'm going to um we're going to real quick just show this with python so I could be anywhere in the world if we deployed this I could be anywhere in the world and basically this same type of methodology will work um we'll start with just our local endpoint so like this local endpoint wouldn't work anywhere in the world but um as we build up yeah we will get stuff that can work uh more globally and the reason is because this hasn't been deployed yet so it's C just on Kat's local machine exactly so I took from the API the Little Swagger docks there I took the request URL that they provided with me so I'm going to just try to make a little request to that spot uh I have too many tabs okay so paste that in um we'll delete this real quick there's a couple of ways we could call this um I think I'll start with just using this URL endpoint and we're going to do a request.get URL endpoint and then we need to pass in our parameters so if we look at the parameters that this is expecting it's expecting a field called text we see that that is defined in our code in our app with um you know right here it's expecting text uh so that's kind of how we're defining it when we you know when we're processing it Downstream we we get text but uh it's expecting a text field so I'm going to pass and then pams equal text and then we could do something like this is some lowercase text or let's just do this is some text um and if we run this code here it doesn't do anything because I didn't print anything but if I set response equals request.get I could do print response uh do Json and if we run this we see that we get back you know the uppercase text so that's pretty cool so this is like our locally run endpoint we run it this way response. Json we get back this is some text another thing that's useful to know about is like I could also access the status code here so like when it's successful you should get a status code 200 so this is all running locally but we're kind of building up to having this um hosted publicly all right um with that I guess is there any ideas for that that API Endo um it looks like so a lot of this is over my head but it's fine I think just try to rewatch it the whole concept like I there might be a lot of terminologies and things but the concept is that you have something and you're trying to package that into a piece of software which then can be accessible by other people um so it's like that everything else is just like details about how to exactly do it yeah so a question can we run um like python notebook files or should we use just Pi files I would recommend just uh python files basically the way that I would think about this is let's say you're doing some data analysis code and you start writing some functions that help you do your data analysis maybe someone else on your team needs to access that type of code and that functionality basically what you're going to want to do for them is Define like what the inputs are what the what the outputs are and then just encapsulate that chunk of data science functionality within a class like we have here um so I would probably like honestly like depending on how you're structuring your python notebooks you probably have like chunks of logic in different cells like you could probably maybe try to break out those chunks of logic in different cells um into you know various uh you know you know each cell has its own little like API call to do that same type of functionality but you're probably not going to want to actually use um you know your IPython notebook to set this API up on the the other side though is like to do this type of thing where you're hitting an API and playing around with like different input parameters yeah you could definitely use a um python notebook a jupyter notebook to like actually access the API and run all sorts of different things so from the client side yeah you definitely could use a python notebook from the server side and actually hosting the flask endpoint or the API you you know you're not going to be using a IPython notebook thank you cool and I don't know if I saw too much on the comments on different things we could do but I just want to show a little bit more complex example of an API endpoint just so you can kind of see us build up and then we'll actually do a more real world example of that book reviewing uh uh idea that I mentioned and I think we have just about enough time to squeeze this all in so it's going to be a lot of information this live stream will be here for everyone um but I'm trying to package a lot in quickly cool that's good so here's the thing is like this is pretty intimidating like it's really cool that with just this dock strings definition and this kind of kind of formatting we get this Swagger spec just through how these libraries are operating together it's really cool that like again just to reiterate that this all in here is generating that website like if I change this to like message and I reran the app or actually I think the the app will rerun automatically uh behind the scenes because it notices I have an update if I open this again we see now we have message here so like the doc strings I'm editing is directly influencing the parameters that we see inside this Swagger dock uh that will let people call these API so very cool but the thing is is like the reason I kind of told people to clone this code versus like write it all from yourself like this is intimidating to try to remember how to write in format just from scratch um so I feel the way that I go about doing something like this these days and trying to generate at least a baseline for my next API call if I'm going to use this doc string format is use our handy dandy uh uh chat GPT techniques and see what it can generate for me so I just want to show a cool little example of like let's say I instead of just upper casing text I wanted to be able to uppercase text uh maybe duplicate it a number of times maybe I uh it it it doesn't get uppercase like there's multiple parameters here what I can do is I can copy all of this little this code here and I can go to our good friend uh chat GPT and again this is just an idea you don't have to follow this format I have gp4 but you can also use GPT 3.5 because more people probably has GPT 3.5 I'll use this but this is like the type of thing that I do when I'm trying to write a new endpoint I might just be like given my template code code below generate a new um API class or generate a class called string generator that can take in a message has an optional par duplication factor which is the number of times the string should be duplicated and an optional parameter capitalization which can be upper lower or none and generate the python code and Doc strings for it this is like not even the best explanation but I'm going to just paste in the code I have already and just see what it kind of spits out okay so I think it's giving me a little more than I need but one thing that I really get excited about is it has this new class I can just copy all of this um I see some pretty good code here and I'm just going to copy this paste it in below we have now two classes I don't know what all this stuff is and sometimes you know chat GPT is going to kind of hallucinate a bit and from doing this a good amount I know that I probably can probably just get rid of that um small changes like I don't need a parser here I can just get things directly from request. args uh but the cool thing here is now behind the scenes by just adding this code and then adding this API add resource generate and api. add resource um uppercase text and I guess it pasted in a little too much but if I rerun this I'm going to try to close some terminals here I have a bunch open again I'm over here in it gave me this weird uh not found URL if I go to slash API docs and I know that this is really small probably on your screens to read oh no we got an error what is the error let's see what might be the error here see just gonna real quick I'm going to just not have any python code in here real quick we're just going to pass let it restart behind the scenes the biggest thing is I want to just show that there's a new API endpoint there and we can then work on getting the logic up and running for how it works um oh no you got to love uh getting internal server errors anyone have any recommendations on how to fix this you probably can't even see all the code right now so if it doesn't work I'll just skip it um I think the thing I just did want to show is like you can start using like API endpoints that you call to start generating like very interesting things using chat gbt um sometimes you run into a little bit of uh issues uh like this but it usually can get you most of the way um they um doing something like this I might have not actually regenerated the server H yeah it doesn't like the um given I commented all this out and it still giv me an issue uh it doesn't like something that I've done here oh it's it's this description here I think probably it doesn't like the double colon can you tell them the zoom error section A little bit does say it again says can you can you zoom the error section A little bit oh okay I think just the terminal yeah definitely so I think the thing it saw oh no is that I had double colons basically in this doc string method and this was because I let chat GPD generate it for me so it definitely helped me a bit but it was basically doing description calling and with this syntax that's very dependent on colons uh having another colon later on with capitalization style um I think caused an issue so I bet you if I now rerun the server and it looks like it restarted now okay look at that now we have two endpoints it has multiple things that we could pass in notice only one is required here um and we have these different you know types uh and the cool thing here is now that we fixed that little error we had I'm going to uncomment this code that we initially had and let's see what happens when we start playing around with this new end point so I'm going to say hello world we're going to duplicate it five times so we should get Hello World hello world hello world hello world hello world and we're going to capitalize it as uppercase execute that uh looks like we got another error let's see what we got here if I go back to the code it doesn't like the type duplication Factor um non in of type string so I'm guessing right here it's actually parsing it as a string instead of an INT if I rerun this try it out hello world five upper execute look at that we get hello world five times with uppercase text and it read all of that via our API call um by getting these different parameters that are defined in the doc string so we have our message which is required here that we specified we have our duplication factor which uh is not required so I wouldn't have to actually pass that and then we have this capitalization value um and then just kind of reminder of how this might look full scale um if I go to our new endpoint which we called uppercase and I do a get uh or sorry we called it generate and I pass in text and I just try to run that um looks like I try to run it in the same terminal basically I can run this code API test I guess I am having issues what did I call this I think I called this message or something message yeah it's not text it's message and that's required so you're not going to get a good response message run that and if I print out the response uh we see we get generated text this is some text I could pass in the optional parameters like capitalization I will say upper I run this we see we now get this is some text uppercased if I run now with a duplication factor and we say that this is I don't know four we see we get generated text like that um and so again using the do the reason we knew that it was this URL was because it's the request URL here and then anything after the question these are the text parameters that we can add and Python and the request Library let us kind of add them in nice more pythonic ways by doing kind of the the syntax we have here um cool so we're running close to time and we don't have this deployed API endpoint yet but let's do that really quick I was hoping to actually connect with uh air table and do some actual book reviews uh in addition to get requests but post requests I would say like my call to action on of that is that it'll be part of a tutorial that I'll post later but I do want to at least show the full scale have a public API endpoint up that you can have someone test and make calls to so that's what I'm going to show with the remaining time here so to do this I'm going to first look at my code we've made some changes there uh I'm going to go ahead and we're on the branch lunch and learn just because I don't want to change up this kind of Baseline code I'm going to do get checkout DB final lunch and learn code that creates a new Branch final lunch and learn code and it doesn't have anything committed yet I can add staged files that we've already have in our GitHub repo by doing git add- this is a nice little trick because sometimes you do get Dead period this will add every file that you have and sometimes there's files you don't want to have so get get ad- just adds the files that are already um have already been added see app.py and requirements.txt um if I then go ahead and commit that final API endpoint code and push that origin final lunch and learn code we now have that pushed to GitHub if I go to GitHub I look at my branches right here we see we have final lunch and learn code that's awesome and here's the fun part uh there's different websites to do this but I think like when we think of deploying often times we think of um like AWS or aour or Google Cloud platform and all of those are great for many reasons but oftentimes if we want to just deploy something quickly there's better Solutions there's quicker easier solutions that have taken away a lot of the complexity out of deploying something so one that I have liked a lot recently is a site called vendor.com uh yeah definitely not the only site that you can do this another popular one is versel v r c l I believe that you could deploy these quickly uh Heroku still is a little bit more of like the original player in this field it maybe a little bit less up toate but Heroku is another one but you can create a profile on a flask application so I'm going to go ahead I already have an account I'm going to create a new service and so you'll have to create an account to basically follow along at this point but there's a lot of free tier stuff so I'm going to just use the free tier to show this um this deployment but build and deploy from a git repository I'm going to do that I'm going to connect our python API example that we've been working off of we'll call this like lunch and learn API um you might want to namespace this like to be you know more specific and unique to your company or organization um with the API we currently set up there's no sort of authentication which is something that you'll want to consider as you make this more robust so like what we deploy here will be accessible probably to anyone and that's not great practices from a um coding perspective like ideally you would have a API key or only be able to run things based on authentic a but for the purpose of this I think it's fine and the purpose of like testing something out quickly it's pretty fine we're going to use that final lunch and learn learn lunch and learn code Branch uh we want it to install the requirements.txt folder uh that has all the libraries it needs um this start command uh you want to have gunicorn app app that just kind of runs the flask app behind the scenes we're going to go to the free tier um and I think that should be it make sure you have if you're doing this on your own make sure you have gunicorn in or gunicorn I don't know if I'm pronouncing that right iny requirements.txt I go ahead and create this web service hopefully it deploys okay we see that right here it's like installing all of the packages uh that we have in our local code that we push to GitHub uh while it does this it might run into an error two and we can resolve that but one thing that I really like to note is like if you have an API key or something in your code and you're deploying to a site like render while we don't have anything right now like this environment variable space is very helpful for doing things so if I had like an open AI API key I might add it as an environment variable here and then I could access it with the code that is deployed you paste in that secret value another thing you can do here is specify the python version so if you need to run 3 you know 10.10 or something like that you could save it as environment variable here and it will know to deploy and as we see we got a little error here um gunicorn command not found is that because um we didn't add it to our requirements.txt and look at that it wasn't actually added here that's my bad add that real quick and as we're kind of nearing the hour I feel like this will be the last tah seeing this actually live and working but I'm happy to start answering questions uh too because some of this might take a little time to build I think we're doing a pretty good job on the chat side of things and people are understand the kind of like the structure of what you're doing so the more exact details you can watch on the replay so you did a really good job just people were saying that as well and explaining how it all works um in the last few minutes I think it would be really cool just kind of explain like the air table stuff like how like what is happening maybe you can also leave that as an exercise for everybody as well as go check out your channel later I think it would be cool to explain how what you can do with it cool I'll say a few words here so I just first off want to just quickly reiterate like look at this Syntax for how to describe these you can generate new get and post requests based on this syntax and you can look up like flask rful and flas flask your libraries to see how to format that as well as use chat gbt but I do want to show that like ideally we would not be just doing these kind of trivial things like upper casing text ideally we'd be pushing to a database uh writing to a database pulling from a database and ultimately there is actually some code that is living in that GitHub repo that is doing a lot of that uh and actually look at that we have our deploy live so I'll show the the final hurrah of testing this with an API end point in a second but worth noting that if you want to explore a little bit further and see how you could integrate this to something more um air table is a great like lightweight airtable.com is a great like lightweight um basically Google Sheets type thing that you can inter interact with programmatically I like it a lot because it is very much like a Google Sheets but it becomes very easy to interact with programmatically you can get an API Key by just going creating an account here on a table going to account or actually going to sorry going to developer Hub and creating a new token here and giving it uh probably read and write scope to your records um and then basically you can start ah where's my table once you create that key you can start adding rows to this little database um via python using the pi a table Library how to do that is shown on the master branch of this repo in book review and app.py so if you look at this code you can see a little bit more sophisticated of AP I calls um and then actually looking at the logistics there's this book review. py file um that has the actual like API setup to pyer table so it's all Happening Here you set up a table and then basically you can run some code using that getting all the records in your tables uh adding records Etc and then that is called in app.py by either you know getting a record we see that we call book review get all records and posting a record and you can look at all the doc strings here too to see how you would formulate the dock strings to generate the URL but this also you know adds a record to that Pi a table I went through that super quickly I'm going through it super quickly not so that you understand every little detail because I know that I definitely wouldn't understand every detail of what I just showed but you just know the code is here on these different branches for you to take a look at and knowing that I will post a video on this but finally I guess with further like kind of this the final hurrah of this session we see that we had a live deploy of our code on render.png currently doing this it might break it cuz we're on the free tier but if I now go to this um URL and go to API docs we see on a like real URL so this is lunch and learn uh API I'll paste it in here so you can see it a little bit bigger but going here we actually get our API endpoints to play around with and I could you know run the duplication factor I could do it lowercase and if I run this we actually see that it is generating stuff and then the final last cool thing is that going back to our little API test endpoint now instead of using this little local thing if you are on your side running this Comm command here and if you watch this after the fact I might have shut down this API so hopefully you can follow the endpoint because I um or maybe I'll keep it up for a bit but run this uh Slash generate or slash um uppercase depending on what one you want to do and I run the python file look at that we actually get a response back hitting the actual server so like this code should work for people and I'll make it bigger ah work for people uh locally ah we're almost there cool so like this is now a live API that you can make a get request to um I added those details of like you know using air table if you want to extend this project I'll also make a YouTube video on it uh I'll pause there sorry I squeezed a lot I try to squeeze a lot into this hopefully uh you know might have to rewatch it to get some of the details but but um I'm happy to stick around if Tina keeps the live open for a couple more minutes to actually answer some more questions thank you yeah I think you did a really good job overviewing everything and everybody like it's okay if you don't understand exact details about things uh Keith is going to make a much more flushed out video about this so definitely go to his channel which is linked um in the description and also pinned in the comments as well and just look out for that video coming out soon but hopefully um that was able to give you a really good overview of how these things work and get your brain thinking about the things that you can possibly do now which is the very big point of these lunch and learns so if there's any questions I think we can stick around for around like 5 minutes to 10 minutes or so uh sounds like it looks like a lot of people ask questions throughout the live as well so totally fine if there's nothing super additional you might like have to look through the recording a couple of times and then you might have specific questions when you're implementing the code yourself thanks so much for all the information thank you Keith definitely it was a lot of fun I love this uh the live the live format is like kind of newer to me I'm uh very used to like recording my uh my tutorials and my uh you know over a long period of time cutting things out so it was fun to try to do this live uh it adds a lot of I think little details that you sometimes don't see in a more fleshed out pre-recorded tutorial like because we generated some uh code Snippets using chat GPT live we had some live debugging that we had to do and that's uh always a little stressful uh on the live stream but I think it worked out well with like trying to figure out you know what might be going on kind of utilizing the strategy of like okay I just wanted to comat out all of this actual python code and then that let me know that okay the actual issue is in the do do strings here and then I could fix the dock strings so like little strategies like that I think are important with the live factor and honestly one of the biggest skills of becoming a very you know a very professional software engineer is the ability to solve things quickly and to be confident that you can work through the issues that you're bound to run into no matter how good you are you're going to run into a lot of issues and it's a matter of uh do you have the resilience to to work through those issues yep I don't think you can give any developer and be like do this on your first go I think that was definitely very difficult to do so I think it was the live format may I don't know Keith maybe you should do more live I should I should I I like that it's pre-scheduled too it's a commitment of like getting something out there and doing a session and and having everyone join and yeah it's fun I think it it's easier to do than pre-record when there's no uh set date or anything you get too much in your head I think when yeah for sure uh and thank you so much much William for supporting the channel I'm really glad that it was useful appreciate itug so go on uh just one call to action I just feel like one thing I just really want to make sure everyone uh I want to stress and just make sure everyone kind of understands with this little API format that uh we went through like I think one thing I would stress here is like we built some pretty simple end points but one thing that I would like love for people to just think about is that this code right in here and this code right in this um get request this could be any python code in the world pretty much like you could write any python code you want so I think that the real magic here is like these programs that you're running and and testing out locally like you have the ability to write you know the logic in here or import logic here and then like deploy it on a render.png when you're working with other developers that you know don't have the data science background that need to run the same type of uh methodologies same types of functions it's the it's the flexibility and the ability to interact with other people and other things and even as a data scientist or data people doing this genuinely I think is really helpful to do uh I don't know if you would agree with that Keith like just knowing how to do this kind of stuff is it technically like on the soft for
Original Description
A 1 hour lunch & learn workshop on Building and Deploying a Python API
Keith Galli https://www.youtube.com/kgmit A Boston-based computer scientist and MIT graduate, known for creating tutorials on Python programming and data science on YouTube. He also works as a data scientist and has gained recognition as a tech YouTuber in the field of computer science.
๐ค Sign up here to get accompanying workbooks, summaries, and notifs for future lunch & learns: https://www.lonelyoctopus.com/email-signup
โ๏ธ NEWSLETTER: https://tinahuang.substack.com/
It's about learning, coding, and generally how to get your sh*t together c:
๐ Lonely Octopus: https://www.lonelyoctopus.com/
Check it out if you're interested in learning AI & data skill, then applying them to real freelance projects!
๐Affiliates
========================
My SQL for data science interviews course (10 full interviews):
https://365datascience.com/learn-sql-for-data-science-interviews/
https://365datascience.pxf.io/WD0za3 (link for 57% discount for their complete data science training)
Check out StrataScratch for data science interview prep:
https://stratascratch.com/?via=tina
๐ฅ My filming setup
========================
๐ท camera: https://amzn.to/3LHbi7N
๐ค mic: https://amzn.to/3LqoFJb
๐ญ tripod: https://amzn.to/3DkjGHe
๐ก lights: https://amzn.to/3LmOhqk
๐ฒSocials
========================
instagram: https://www.instagram.com/hellotinah/
linkedin: https://www.linkedin.com/in/tinaw-h/
discord: https://discord.gg/5mMAtprshX
๐คฏStudy with Tina
========================
Study with Tina channel:
https://www.youtube.com/channel/UCI8JpGrDmtggrryhml8kFGw
How to make a studying scoreboard:
https://www.youtube.com/watch?v=KAVw910mIrI
Scoreboard website:
scoreboardswithtina.com
livestreaming google calendar:
https://bit.ly/3wvPzHB
๐ฅOther videos you might be interested in
========================
How I consistently study with a full time job:
https://www.youtube.com/watch?v=INymz5VwLmk
How I would learn
Watch on YouTube โ
(saves to browser)
Sign in to unlock AI tutor explanation ยท โก30
Playlist
Uploads from Tina Huang ยท Tina Huang ยท 0 of 60
โ Previous
Next โ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
How to choose between software engineering and data science | 5 Key Considerations
Tina Huang
How I got Software Engineering and Data Science Internships | Computer Science Job Search Part 1
Tina Huang
How I Became a Data Scientist | Computer Science Job Search Part 2
Tina Huang
3rd Year Statistics, Data Science, Computer Science Resume | Reviewing Your Resumes Ep. 1
Tina Huang
How to learn SQL for data science interview (the minimize effort maximize outcome way)
Tina Huang
3rd Year CS Resume (and asian drink) Review | Reviewing Your Resumes Ep. 2
Tina Huang
Are you a student? If yes, this is the best data science project for you!
Tina Huang
The Ultimate Guide to Land a Data Science Internship | schedule and time management survival guide
Tina Huang
Upenn MCIT Program Details and Real Student Experiences - Dr. Arvind Bhusnurmath
Tina Huang
Real Data Science SQL Interview Questions and Answers # 1 | Data Science Interview Questions
Tina Huang
3 More Unique and Impactful Projects to get a Data Science Job
Tina Huang
Real Data Science SQL Interview Questions and Answers # 2 | Data Science Interview Questions
Tina Huang
THANK YOU FOR 1000! | Proper intro | Random facts about myself
Tina Huang
A day in the life of a data scientist (FAANG data scientist remote)
Tina Huang
SQL Data Science Interview Questions and Answers (interview style walk-through) | Question 3
Tina Huang
Biology to Data Science (data professor's tips on how to get a data science research position)
Tina Huang
SQL Data Science Interview Questions and Answers (interview style walk-through) | SQL Sundays #4
Tina Huang
Data Science SQL Interview Question Walkthrough | SQL Sundays #5
Tina Huang
Data Science Resume Round-Up With @KenJee_ds - Episode 2
Tina Huang
SQL Data Science Interview Question Walkthrough | SQL Sundays #6
Tina Huang
Data Science vs Software Engineering Interview | 3 Key Differences
Tina Huang
Data Science SQL Interview Question Walkthrough (real interview style) | SQL Sundays #7
Tina Huang
The data science resume that got me my FAANG (MANGA?) job (entry level data scientist)
Tina Huang
Data Science SQL Interview Question Walkthrough (real interview style) | SQL Sundays #8
Tina Huang
Interview with a quant trader
Tina Huang
How I chose my masters degree (as an international student)
Tina Huang
The software engineering resume that got me into FAANG and Goldman Sachs (internship)
Tina Huang
3 tips to avoid debt for a masters #SHORTS
Tina Huang
A hard work day (ft. new NLP project) | FAANG data science isn't chill | vlog 1
Tina Huang
The comments sections are WILD | YouTube sentiment analysis - Data science project for beginners
Tina Huang
Do you have what it takes to be a great data scientist?
Tina Huang
How to learn data science in 2022 (the minimize effort maximize outcome way)
Tina Huang
A productive day as a data scientist | day in the life of a data scientist vlog #2
Tina Huang
How to learn math for data science (the minimize effort maximize outcome way)
Tina Huang
Internship that made me rethink my career...(technology summer analyst at Goldman Sachs)
Tina Huang
How to get a data science job
Tina Huang
cake and big sister advice ๐ค
Tina Huang
the most underrated data job in 2021
Tina Huang
My career changing computer science masters degree in 15 minutes (Upenn MCIT)
Tina Huang
Data science interview tips (product and technical interviews)
Tina Huang
Needed to learn javascript in 3 hours - would not recommend
Tina Huang
from management consultant to software engineer | Humans of MCIT
Tina Huang
Overview, Review and Study Tips - Google Data Analytics Professional Certificate
Tina Huang
Overview, Review and Study Tips - Google Data Analytics Professional Certificate (condensed version)
Tina Huang
Watch this video before applying to Georgia Tech OMSCS
Tina Huang
How to self study technical things
Tina Huang
What's the best certificate for data analysts? Google vs IBM Data Analyst Certificate
Tina Huang
FAANG Data scientist reviews: Datacamp, Dataquest, 365 Data Science
Tina Huang
How I would learn to code (if I could start over)
Tina Huang
The quant trader interview guide
Tina Huang
We code a trading bot live! @jacobamaral
Tina Huang
Why you should have a portfolio website
Tina Huang
60k cooking and Q&A (ft. Uncle Roger fried rice)
Tina Huang
How to self study using MOOCS (Udemy, Coursera, and other online courses) | self study online
Tina Huang
Data Science SQL Interview Question Walkthrough | SQL Sundays #9
Tina Huang
Watch me build my portfolio! | How to create a portfolio website
Tina Huang
How I stop myself from burning out
Tina Huang
How I take notes - Tips for efficient note taking that speeds up learning
Tina Huang
How I design effective study plans for ANY SUBJECT (and stick with them) | trading, coding etc.
Tina Huang
How I'm learning to trade (forex swing trading)
Tina Huang
More on: Prompt Craft
View skill โRelated AI Lessons
โก
โก
โก
โก
When AI Asks for More Electricity Than a Country Can Imagine
Medium ยท AI
You Are Not Behind. The World Is.
Medium ยท AI
Career choice with the advent of AI - pure Computer Science or learn software with a background of core engineering area
Dev.to AI
The AI Hype Cycle: Calm Before the Next Breakthrough?
Medium ยท Programming
๐
Tutor Explanation
DeepCamp AI