What is FastAPI | FastAPI Mock Interview | Interview Questions for Senior FastAPI Developers

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello everyone we are back with another round of 2d marketable cities my name is joyose and i'm a tech lead at turin and i'm from montreal canada but today i'm not in canada i am in lisbon portugal and believe me is quite hot today so today i'll be interviewing prep dodge for the role of an experienced fast api developer okay and sticking to the end because this interview will also blow your mind so let's get started hello prabhas uh first of all uh how are you doing and how is your day doing so far hey jose i'm doing pretty good the weather is pretty hot here as well i'm i'm speaking from punjab india and it's hitting the high parties here um but i think we have a bit of a rain going on outside today so doing pretty good weather it works great thanks for asking how are you doing i'm doing great today's a sunny day and believe me i prefer snow okay all right so let's let's get started man so uh could you please uh introduce yourself and tell me a little bit about your background okay your professional experience and then i'll take from there i'll ask you a few questions about this tech stack and then let's see how it goes sounds good sure sounds good so uh i've been uh working as a python developer mainly i uh prior to that i did my masters in computer applications um i started working out as a machine learning engineer and i've been working mainly on python because of the deep learning stack fits in together well i have been working for three years now and fast api has been my main tool to you know deliver all the machine learning models that are developed as uh consumable solutions to uh the clients cool uh and apart from uh fast api do you have experience to use another framework from python another type of camera like flash jungle to you yeah i i do i do i have also used django i have migrated projects from django too fast api i have also likely used for some of my college projects uh so yeah okay so uh you mentioned have experienced migrating jungle applications to fast ap applications is that correct yeah oh i'm gonna talk about it later so um could you please tell me a little bit more about some uh fest api project that you have been working on sure uh there was a pretty cool one which i'd love to tell you about uh so we had this requirement where we had to process the user's selfies into you know portraits and apply neural style transfer so basically your selfie would go in and it would gave out a portrait a 16th century portrait of you renaissance style or a disney pixar character that looks like you or a sketch of you and we we use fast api to build this whole back end architecture where we had two micro services one was to process the selfies which would go uh into the deep learning module and then that would give back the end result so both of them were using fast api uh for the processing um the the communication was really fast and asynchronous because of fast api's uh inherent uh speed benefits and yeah that came out great and i have follow-up questions so uh you mentioned uh getting the the the face of the user okay the selfie but it's for it it was good for photos or videos yeah also it was real time or post processing it was built for photos and it was post processing it wasn't real time we did have plans to deploy something similar to the device itself but uh that would require a very robust device cool all right great so um and in my previous question you mentioned that you have experience migrating jungle application to fast api right now first of all what's fast api okay and how fast api is different from jungle application or even flask application class kpi so uh fast api actually takes a more python it's it's a web server that you can use uh to deploy restful uh applications or even uh develop full stack web applications uh so the the inspiration came from flask and django so here if you see it on the spectrum django is like everything included batteries included that's how they determine and flask is like this minimal uh very easy uh framework fast api gives you the best of both worlds where development is easy because anything you need can be added on through open source packages and you can even replace them for your own packages or if you don't like one package you can switch it out for the another and then you also have the ease uh it's it's lightweight like flask it's uh [Music] it's it's faster because it inherently out of the box it uses uh asynchronous processing on it beats django by by whatever it by uh an order of two in terms of every synthetic benchmark so that's that's uh my understanding of why we played with past api okay cool so you mentioned their uh fast api is like the best of both right jungle and flash can we have uh ui do we have a ui for fast api or it's just for api um so there's two things uh when you mention ui uh one is that one of the very cool features about fast api is if you're just uh making a a back-end restful server you would get a ui which would describe what each of your endpoints takes in as input and uh what is if you it it suppose the open api specification so it will give you a ui to interactively uh view what your endpoints look like and then on the other hand you have ginger to templating engine uh also included where you can render html pages and provide uh fast uh like develop it like a full stack web application okay so cool in your previous answer you mentioned that fast api can handle a synchronous task right uh and i'd like to hear a little bit more about that and my question for you is what's the difference between wsgi and asti what do you understand by wsji and asei and what's the difference between them sure so wsda and asga are both standards for web server gateway interfaces wsdi is inherently synchronous whereas uh asgi is the spiritual successor to wse which is asynchronous inherently fast api uses asdi out of the box whereas django and flask are slowly moving towards the asgi standard sure okay so the difference between the both is how they handle the incoming requests the wsdi uh has worker threads which are present which are waiting for the request to arrive and then when a request is arrived it's handed off to a worker thread but that significantly i mean oh it's it's one thread uh it's one uh new process for requests or uh it will reuse this same process for many requests it will reuse once it has uh once it has for example if if the pro if all of the workers are occupied it will wait for one of them to get free and then assign it but the the workers are a static number and the common convention is to use twice the amount of cpu cores that you have as the number of threads got you yeah correct and and how about asgi yeah so asdi being asynchronous it works somewhat like uh uh somewhat like we see in javascript it has an event loop which picks up processes uh based on when they can be returned and it can leave off certain processes which are you know maybe i o bound or something to be picked up later and the the benefits uh based off of synthetic benchmarks uh asi is like about four times faster than wsti standards on on many synthetic benchmarks which include io and you know database access and just raw processing and how do you test uh if specific locally so i would use fastapia's inbuilt test client it's it's fairly intuitive and simple to use uh you just basically add test underscore behind the function name that you want to test you provided the dependencies you write your test case in that and uh that's uh that'll run unity that's right this is the unit test correct all right and okay uh do you have an experience okay uh using uh fast api instead dockers what do you need to use press a pair inside dockers so all you need is a python uh is a python interpreter so python installed on any linux docker image i use mostly the python 3.8 or 3.9 docker image that is already built you can just pull that from docker and start installing the requirements uh the packages that you need to run your application and give the last command as a uvcon run on your host port and expose that port and one more question we got these uh this part does fast api work with python 3.7 only we fight on three plus i don't have experience with the uh using it on python 2.7 and i'm not sure if it does it is a fairly recent framework i i'm not sure if they support i think python 2.7 did hit end of life by the time fasting thank you cool and i would just like to come on our fight on the developers here so this does fast api work with python 2.7 or only for python 3 plus version so let me know in the comment section below and then let's see how it goes so uh speaking about uh as synchronous okay let's stick with this uh how do you create middlewares what's what's the middleware a middleware is basically just a function which is kind of a wrapper around all of the processing that you do inside your api so if you want to do something before the request comes into your function or after the response has been generated and before it is sent out to the client that's what you'll use a middleware for a good example would be authentication middleware so when you're when a request comes in you want to make sure that this is something that has access to uh has the correct token to access this api and the other one would be the request processing time being returned so the authentication would happen before uh your business logic is run and the process time would be after it is done both of them can be done through a single middleware cool and how how do we use middleware in a request for example let's suppose they have a middleware for the as you mentioned for authentication how do we connect the middleware with uh requests um so there are two ways we can create our middlewares uh one would be create a function and just decorate with app.middleware and http in the colon or we could uh create a class uh class inheriting from starlet's base http middleware and implement the dispatch method both in in both the cases we would the function would expect a request object and a call next object which which would mean what to do after this middleweight has been called [Music] okay and how can we use uh much for midways uh so while creating the fast api app you have to register these middlewares uh during the instantiation so that's where you can include and the order of these middlewares matter so whichever one you put above would be the most up the outermost wrapper or the first middleware to hit so generally it is the exception middleware that is the first one and then your authentication and then so on okay so they are synchronous or asynchronous let's suppose i have two middlewares let me do it to check the application uh token for example and the other middleware is to extract the user and i don't know use a map okay let's suppose the request payload is too big and then that function use only uh the email and then i want to check this email the user email okay first i have check authentication and then i have check user email if it's a valid email does it work synchronously or in parallel it works synchronously but the underlying logic can be asynchronous middleware is by definition because we are providing them in a certain order they are working in a synchronous manner but if a middleware has a long standing task which is not required for the step below that that long-standing task can run in its own uh while the next task executes and who decides that decides what who is responsible to manage that so if you it will wait or it will run in parallel we we can implement both asynchronous and synchronous uh middlewares so that's that's totally up to the developer how we want to okay great so and my next question is related to course okay so the course middleware implementation are restricted by default right and so how to use how to use a course in um site context um so this this is a common problem everyone faces uh absolutely yes when we start developing anyway okay why can't i access this so i have found a couple of uh headers that you can set in the course that you can use in the course middleware which is basically accept headers accept uh accept regex so you can provide a rejects for which origin you want to accept requests from or you can provide the exact names also there's another there's another parameter for that i don't exactly recall their names but uh yeah so that's how you can uh watch it and how does uh fast api manage dependencies so fast api has its own depend uh an inbuilt abstraction which can allow you to define uh what are the dependencies for a certain endpoint so when we when during runtime these dependencies are evaluated and that's when these are loaded we can also mock these dependencies by uh by just uh by using this convention called dependency overrides i believe uh and that's that's useful for you know testing features where uh or where you might have a cost attached to them when you don't want to test uh hundreds of times so uh yeah cool have you ever heard about pydentic uh yeah i have actually used it do you have experience with identity yeah i do use it that's cool so what are the different sorry what's what are the benefits of use it so pydantic is a library which allows the serialization and de-serialization of input requests it converts them into a python class which can be used on per request basis and then it also abstracts out a lot of the validation parts that we need to do on per request and gives us a very neat and concise api to implement those validations we can also use it for object relation mapping so you can use it for converting an input request into an object uh for which which represents a row in the database and all of for all of that you just need to manage one class so that's uh another new thing what you mean is i can uh fetch the data from the database and convert that in array of uh specific class right this is about the mapping right yeah i can i can convert a class object in object to that will insert in the database and vice versa correct what do you understand about uh core routines so code teams are like functions but they are they're they're what facilitate the asynchronous programming part of python so coroutines were introduced fairly recently in a late python 3 version only and they are basically a function which is yet to be executed so to be executed and evaluated so to evaluate it we need to use the await keyword anytime you run an async you call an asynchronous function it is going to return a routine object and then you have to await it for it to evaluate into its final value cool that's great and so that's that's actually triggering my next question what uh what are background tasks in specific guide so background tasks are basically uh it's it's a neat api provided by fast api which lets us do tasks which are not essentially required in during the processing time of a request but they need to happen outside of that time so it's it's it's a way of uh taking out the unnecessary logic which is uh which can add up to the the processing time of a request and doing that processing in the background when there are no requests or after that give me an example uh yeah so for example uh if you use logging right every application needs logging so whenever you're logging out to a file every time you do log dot n for log or debug it's essentially an i operation that's happening and that is synchronous so that those i o operations don't exactly need to happen when you are processing that request if you just take out all of the logging and do it after the request it serves you well as well and in the in the process you will end up saving uh maybe a tenth of a second or a fifth of a second and these kind of times matter when you're working on an api which requires uh hundreds of requests per second okay so the worst thing is it will flush the request right return to the user and then proceed with uh i opened yeah with this we come to the end that was my last question so thank you for uh attending this meeting today what's my pleasure to talk with you and to everybody else uh if you enjoy this video uh if you enjoyed this mock interview series let me know in the comment section below what kind of marketing view would like to see here and then just drop a comment there and then we are going to make it for you okay if you enjoyed this video please give us a big threat in thumbs up for this video and check out our previous mock interview there's a lot that you can learn and subscribe to our channel if you are not subscribed already and that's a wrap i hope to see you all again and thank you prabhupada again and have a good one take care yeah bye [Music]
Info
Channel: Turing
Views: 6,249
Rating: undefined out of 5
Keywords: FastAPI, FastAPI Jobs, FastAPI Developers, Developer Jobs, Mock Interview, FastAPI Mock Interview, FastAPI Remote Jobs, Remote Jobs, Turing Remote Jobs, Remote Developers, FastAPI Remote Developers
Id: qLdqNEjYQtI
Channel Id: undefined
Length: 22min 34sec (1354 seconds)
Published: Tue Jul 19 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.