Flask Webcast #3: Circular Imports

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome to the flask webcast episode number three this is going to be a discussion on simpler imports and in particular how they sometimes make the life of the flask developer hard so before I begin I wanted to mention a a couple of things first for those that haven't heard I have made an update to the flask mega tutorial site which is at cursus da miguel greenberg calm and this is a completely new site different from the old site there's a new pricing structure and also for those of you that already have the tutorial that purchased it on the old site then you can find out how to upgrade and and transfer your license to this site by going to this where is the old site link here you have all the instructions ok so next let's go on to the questions so this is the the webcast there's there's a few people already there so if you want to chat you're free to chat with your with all the people that are watching if you want to send a question that I'm going to answer at the end of this webcast what you can do is you can write question : and then ask the question so for example how do I ask a question and of course you're not going to see anything but then I have a little thing that's watching the chart which is webcast dot miguel Greenberg calm and this application captures all those questions that have the question : prefix and you can come here to this website as well and then vote on the questions that you want answered and then at the end I'm going to answer them in order from the most voted but usually at least a previous couple of times that I did this the number of questions wasn't that long and and I went through all the questions anyway but but I'll start from the ones that are more interesting to people so I think that is it for the introduction so I'm going to start with with the main topic some secret imports and just as an example I created a very simple application that that doesn't use flasks but it has a simpler import so here you have first top pie which imports a second function from a module called second and then this module defines a first function so we have a first function here and a second function on the other module so here you see the second module and this one imports the first function and so so this one wants to import first to find second and then both at the end called the two functions so if if I try to run this let's see I'm going to go to the correct directory and there we go so if I run first I get an error and the the error it's basically I'm going to try to describe it so if I say Python first up I then the Python interpreter starts from this line so it start sparking first dot pie and when he sees the import it stops parsing this file so it doesn't continue here and it jumps to second apply so in first up I Python has not seen first function yet so now it goes on to second apply and here it gets an import from first function and in the general case this will be an error so Python knows about the first module but it so far it hasn't seen the part of that module where first function is defined so it will give you an error and that's a severe dependency now if you look at this error closely you're gonna see that the error is not on second of Pi it is on first up pi and this is a tricky aspect of Python imports that that I think it's one of the most important things that you need to be aware of the expected way in which this will fail in which is that second up I will have the error will be correct if you had a third module that is the one that you run so here I added a third module rendered PI that imports first so now first it's not my main module anymore and if I do Python run doc PI now I get the expected second PI in line one failing with the city or dependency so the question is what happened here why this is if you look at this this is progressing a little bit more so it went from let's see it went from first to second and instead of failing like we expected it went from second to first and then first failed and this is this is something that confuses a lot of people and the reason for this is that when python import your main module the one that you put in the command it does not call it with the name of the module it calls it main or actually it's done their main like this and you've probably seen this a lot of times at the bottom of a lot of scripts and this is this is the name of the main module so in this example here at the top where I import first as my main module I have a main module so this is done their main Python shows first by but internally it's a dunder main so then their main imports second and then second imports first and python does not understand here that first refers to first up by which is called the under main and instead imports a second copy of first up i or the name first so now you have the under main that imported second up i and then second to buy imported first up i in a second copy and then first up by the second instance then fails with the secret dependency when it tries to again go back into second so the i would say that the the best advice I can give you to avoid this particular very confusing issue with with imports in Python is to make sure that when you write your application and more specifically when you do flask applications that you eliminate any possibility of having a circular dependency on your main file and this is this is exactly what I did with this little example by making my main module a third module that only imports one of the files so by doing this then the main module the dunder main module is going to be run to PI R and oppai it just has an import so it has no problems in circular dependencies but then everything is okay so remember that that's a very important lesson so so yeah basically make sure that you don't use your that your main module is never at risk of having several dependencies by making it extremely simple so let's talk about how to solve this so the problem here is that both modules are importing the other one before they define their own contents so the the standard solution to to solve this conflict is to go to the module that that runs first so in this case it would be first got by and move the import that grabs stuff from the other module below all the symbols that the second module wants so we know that second up pie needs to import first function so if we move this import below first function now we have addressed they we have addressed the circular dependency because now when so we're gonna run from run dot pi and render pi is going to input first first is going to define first function and then it's going to jump into second function into second up i and ii up i when it tries to import first function will find that it is already defined and everything will work and just to demonstrate if i say random pi now both first up i and ii of pi are able to call these example functions so i mentioned that you should avoid having any risk of secret dependencies on your first module and see what happens if i say like the previous time if i start this from first stop i we still have a never this even though this solves the cyclic dependency with it between first up i and ii up i there's still a problem because first lap i is called the under main and and then the under main import ii and ii wants to import first not it doesn't know about the under main so so then you still have a circular dependency so avoid this okay so that's the the generic introduction so what i was planning to do for the rest of this webcast is to show you a flask application that is a single file and i'm going to go step by step breaking it up into pieces and and doing you know migrating it basically to the recommended file structure where you have multiple packages and modules so the application that I decided to use for this it's so here is a plot PI so this is an application that I created as an example for an old blog post on on database soft deletes so the topic of the application that does not really matter it shows a way to to delete entries in the database without really deleting them with just keep keeping them you know with the martha's delete it so that that really doesn't matter but I think this is a good example because it has a number of things that you will have in larger applications so so there is a there's a utility class that implements some additional features for database queries there are database models and then there is an API with a bunch of routes so we're gonna take this and break it apart into a lot of pieces so the first thing that I do well first I should say that I always start my projects my flash projects as a single file so this is how all my projects begin and then I migrate them into a more more flexible structure as the project grows for projects that are very simple I find keeping them in a single file so I keep making changes to the project and this is something that I always tell people that it's it's good that you are prepared to migrate your application to a different structure but by applying small changes progressively as as you as you grow your application so what I do switch to this directory and I'm going to create a second terminal here so I'm gonna I'm gonna run the application and before I begin a migration to a different structure what I always make sure that I have a way to test the application that's very important because I'm gonna be moving code from between different files and it's very easy to make mistakes and pretty sure while you see me do this and there's going to be several mistakes I'm gonna find those errors with my tests and that is how I'm going to be efficient at fixing them so for for the tests I have two things that I combined into a tox profile so have a a tox project for those that don't know talks is a it's a very useful test runner so you can define what tests you want to run in a tox dot ini file and then you say talks and oops I haven't ever I have the environment activated and let's see so so talks runs a couple of things here and the output it's maybe a little bit noisy but first runs flake eight which is a linter this detects any syntax errors or any style problems in your Python code and then the second pass is some some unit tests or actually some integration tests that basically send requests you can see that the application running on the Left received those requests and this this set of tests basically create a user and then get the list of users and and then create a message for that user and shows that the message was received so this basically exercises most of the endpoints in this API then at the end if you see your green that means that everything is working so so we have a working application and now I'm going to start breaking it apart so the first thing that I'm going to do is I'm going to separate the configuration and this isn't usually this is not a problem with silkier dependencies but I like to keep the configuration separate because many times the configuration needs to change between development and deployment or production and having it in the code it's going to inconvenient it's easier if you separate your configuration into a file to standalone file so I'm going to take these two configuration items I'm going to create a configure PI module and add them here I'm using this base there so I'm going to move that to and and then I need to import OS and I'm for this project I'm going to use the standard variable formatting for configuration you could use a class I've got many times I use a class as well but for this one I'm going to keep it simple so just variables so there's my config and then I can go back to apple pie since I am NOT going to actually I'm going to leave those there here I'm going to replace this with app config from object and the object is going to be this module which I need to import so there we go so now so this is going to reload on its own I'm going to run the flake eight pass and this is going to demonstrate oh look at that it didn't find any mistakes what's going on here okay so that's interesting so base there it's not used it should have flagged that but anyway flag it did not detect that so I'm going to remove them by hand and try it again make sure that everything remains about it so what I'm going to do is run the full test now and make sure that the requests are also ok and everything continues to work so so now we have the configuration separated from from the application so now I'm going to start doing the important changes and since I'm going to start creating additional modules having then here at the top level it's not really a great idea I I always like to have my configuration at the top level because this is a Phi that I usually change sometimes I have multiple versions of it but but really for for applications that have multiple modules I prefer to have all those modules inside a package so I'm going to start then by creating a folder directory where I'm going to put the refactored application and you've seen me many times I call this app and that this confuses some people so today just to show you that you can I'm going to call it my app so this is gonna be a different name and you can call this with the name of your of your application well you know whatever it is so I created my app folder and then I'm going to tech take this app top I the entire application minus the config and drag it inside so now it's inside the package and I'm going to rename it to dunder init so in case you don't know this is this is a special name when you have a package which is basically a directory with Python code inside the the dunder init file is special because it's it's automatically imported when you import the package so this is now you know the entire application now is the my app package so what I've lost by doing this is the the main script in the top level so what I need to do now is create a new top level script so I'm going to create a new file I could call it a plot PI or something that I prefer when I have a bigger application that has a complex structure to call it whiskey to PI which is kind of similar to to Jango so now I have a whiskey to PI and here I'm going to say from my import app so if you look in it up I have my my flask application there and this is what I'm importing here so let's see if that change is working you can see here that the flash loader when you make that kind of big change when you move stuff around sometimes gets confused and you can see here that it did not reload so I'm going to rerun it and now let's run everything all the tests so so if you look at the the integration tests they're working so the application is still functional but we have some problems in the lender we have unused import in whisky depay and I'm missing newline okay I'll fix that so that's the new line and of course in this case a flake eight is saying that I'm pulling something that I'm not using but I need to do that because this module is going to be used by flask so I'm going to tell flake eight to ignore this by adding a no QA flag and if I repeat the test now I'm all green there we go so okay now we have a package and the package has everything in a single file so we should start breaking this up into parts so something that is very common is to move your your database models to a separate separate file so let's start with that I'm going to create a model start PI and this is going to have all my database stuff this is special this is not a database model but it is related to the database so I'm going to keep it with the model stop I would new module module where I have all my database stuff so what I'm going to do is I'm going to grab the three classes so the two models and the query class and just paste them here and this is a the first instance where circular dependencies can make your your life miserable so the trick to avoid problems as I said before you need to move the import on the module that runs first which in this case it's going to be in it top PI you need to put it after all the things that are the other module needs and since the contents of this new module that model start by is here the best place to put the import when we eliminate all this is right here so I'm going to remove this classes that I copied and I'm going to import from my app import models right there and since this is going to also be a flake eight violation and going to flag it as okay with the no QA comment so now I imported my models actually this is not right I need to import user and message because those are actually they're used they're using the routes below so instead of importing the whole module I'm going to import specifically that these two that I need so there we go now on this one we we need to add some imports so this this base query needs to be imported I'm going to copy that it's this one here we only need a base query and I'm sure there's more but instead of wasting time trying to find them by hand I'm going to run flag eight it's going to eat me all the errors lots of them and this is fine this is not worried me in the least so there's a lot of references in models to PI for DB there's a three for URL for okay so let's start with that so we need DB URL for so from flask import URL for and then DB is from our applications so from my app import DB there we go and then here at the bottom we have in the under in it we have base query is an unused import now because I moved it to model shop I so here base query needs to go let's try again and there we go now it's fixed and now we have an application with two modules let's make sure that the tests or work that's all let's try again I think it might have been yeah there we go I think this reloaded didn't didn't restart in time I used to early after a modify the file so anyway everything is working so now we have a model stop I separate from the application in some cases people don't want to have all the database models in a single Python module if you have a lot of models then this this file could end up being pretty big so so I'm gonna keep going and instead of staying with model stop I I'm going to create a package so so this this module now I'm going to refactor it into a package let's make a models subdirectory and like I did before I'm gonna drag this into the package and rename it into dunder init dot pi let's see so now I think let's give it a try I think everything should continue to work once again this apparently did not press Start there we go let's try it and see what happens yeah so everything continues to work good I'm good at this so what we can do now is we can break this this big dunder init into one file per database model so and I add a user to PI and a message not pi so I'm gonna take you sir I'm gonna remove it from here and say from my app models user important user and I replace it with an import that's equivalent and then I'm going to put it here and then I'm going to do the same thing with message so message disappears from here it's replaced in the same place with an import and in this way I completely avoided any problems with circular dependencies so I need to resolve some imports we definitely need DB here and we need URL for my chest right here so from flask input URL for and start with that and we need the same thing in the other model we go this class preferences that other the query subclass so I'm going to let's see yeah I'll put it in a separate so I'm gonna do a query got PI and move this one to so now we have everything in their own module and this is going to be from my app model slow query import query I think it was soft leet should I remember that name I'll fix it if it's not right query with soft bleat we go so you see now any top pie is empty this query with soft delete it's used in here use of no pie so I'm gonna put it here as well and now notice that any top pie has no code now so really after all this refactoring I don't need anything here this can be an empty file and you've probably seen in many applications that the dunder init files are empty because there's nothing to do there and this is usually applications that that import every symbol every class or variable from their actual module which is a practice that that I really like so I'm going to check I bet there are still some problems yes message by needs a couple blank lines okay that's like eight and fourteen pipe eight and that's it I guess so the real order this time worked so let's try to send some requests and see if it works and it doesn't once again i I did it in the middle of a restart let's do it again okay start that oh I think I know what it is right what did I forget I forgot here to import that's interesting that this isn't flagged as an error so these imports need to be updated now what is the error that's that's interesting oh I know it's in the in the debugger I don't have I'm not running a web browser client so these errors go to the debugger message and both need no QA oops this is lower case okay let's see I'm gonna restart just in case well okay great so can I go here I'm gonna just running a web browser oh no app right so this is interesting hmm it's interesting that the ever this is something I I need to okay yeah I actually I wasn't paying attention the others here okay yeah I'm distracted as you can see okay fine so it's risky top I this needs to be updated so here's the error cannot import name from app models query input query with soft delete hmm oh this is missing imports here from was it there we go let's try again if we loaded so we have undefined name DV in query got PI so we need it from my up import DB there we go let's see no new line let's do it so flick eight now it's fine and this guy let's see continue have errors interesting that this is something I need to look into with wood flask that the error does not appear here cannot import base query what was this I got our input wrong oh okay let's see see you there we go okay so so now we have the application and we have a fully fledged models package or sub package with all the models in their own little little Python module and this is now you know very flexible and you can continue growing this this way and you see that I have a bunch of errors but none of them where were circular imports which is the important thing by by using this technique of replacing code with an import when you extract it into a separate module you avoid that problem completely so how are we going on time 9:45 okay I'm going to keep going a little bit and then you check how are we doing on questions we have no questions okay I'll keep going if you have any questions go ahead and write them in the chat in case you missed the e at the beginning you need to go to the chat the link is in the description of the YouTube video and you need to write your question with the prefix question : so if you write question : and then the question then it's going to magically show up here and then when I'm done with the presentation I'm going to answer them but if there are no questions great no problem so okay so the the next step that I will do here if I wanted to refactor this is to take the API routes all these routes and move them into a separate module I'm going to start with a module so I'm going to create a I'm going to call it API drop.i and then I'm going to grab all these remove them from here replace with an import in the same place from my app API see input API I'm going to import everything from that because flask needs to see those and then I'm going to copy them in the new API module so here I'm going to need a bunch of things I'm going to need up from my app I'm going to need the models actually user import user from my app models message import message and we need URL for I can see it there Jason if I request here's request and let's get the remaining ones through flick okay so we need DB and then we have now we have request URL foreign JSON if I are unused in dunder init so under in it JSON file you're a foreign request they go away and here in API we need also DB which we which I forgot to include C and now according to the linter were good they separately restarted so I'm going to get and run whole set and yeah we started at the same time okay one more time there we go okay so now we have all the API routes in a separate package actually I'm sorry in a separate module I could do the same thing that I did with the with the models and make it into a package that will work exactly in the same way so I'm not going to repeat myself but what I'm going to do is it's something that you've seen in many larger applications which is that they don't define the application here as a global variable they use the application factory pattern which provides some benefits especially for testing is it's very convenient instead of having a single application that's a global variable to be able to create an application on demand so each test can have its own application created and basically that allows the tests to run each test to run in isolation with a brand new application so what I'm going to do as a first step but basically the the what you need to do to create a to migrate to the application factory pattern is to have all the references to your application instance removed from the global scope which is basically this this these are all these references need to go and the solution that flask offers for that is to replace the application with a blueprint which is basically a container for four routes that then you can attach to the application later on when the application exists so I'm going to create an API blueprint I'm gonna call it API and then I'm going to let's see I'm gonna replace up route with API route all of them there we go so now we have a blueprint I'm gonna import blueprint from flask and this is now a blueprint so it's completely independent from the application in fact I don't mean that I shouldn't need the important application anymore because it's not used at all so when I go back to here now I need to attach the blueprint to the application so that all the other routes that are defined in it are exposed and so here's one more time a very common place where you have secret dependencies so you see that this this module requires for example DB right so DB is here so we need to make sure that when we import the API blueprint with with after DB is defined and that is going to prevent the secret dependency if you put it here then it's not gonna work so I'm gonna put it right after the extensions so from my app or API import API and here I called so I have a pi/2 pi and inside it I have an API module so I have API and API so these are these are different so to avoid confusion I'm going to do is I'm going to call this API blueprint when I important so in this module I'm gonna refer to it as a hippie like API blueprint and now what I'm going to do is say I'll register blueprint API blueprint there we go that should do it now we have an API blueprint let's check this step is working okay module level import not at top of fine right it's this one I need to make an exception because it's okay I know it's okay okay so that's working and now let's try the whole thing I'm not sure it did again every time I start the tests for the first time the real order except and tries to real the app okay we have an error so okay could not build URL so this is a URL for error and that's correct I forgot so if you look so now all these routes are in a blueprint so when you say URL for this needs to be prepended with the blueprint name and i forgot about that so what I'm going to do yes I'm gonna do another for place should be not this one standard place and I'm going to replace your and for and the first quote and that it's going to be URL for API dot and that is going to think add the prefix everywhere yeah and then I need to do the same thing in the models which also have URL for so there and there so I'm gonna save save and save and let's see what happens okay so now everything is working we have we have an API blueprint with a very little effort so what I'm going to do next is create the application Factory so here in then they're in it for for the my app package I have everything in the global scope and all I'm gonna do is I'm just put it inside a function the function is going to return the application application and what I need I need to handle the extensions the extensions in flask even when you use the the application factory pattern they remain a global in the global scope but you have to change the way you initialize them because you don't have the application in the global scope you just initialize them with no arguments and then inside the application factory function you say in it app you pass the same arguments that before you passed in the constructor and let's see if that does it nope and once again I'm not getting the ever reported here in the console I mean I have to find out what's going on with that flask should show the arrow here but anyway I'm going to use the trick of oh right yeah okay fine yes so now I change the the create app and so now the whiskey top I the top level file that flask is using to run the application it's now invalid so this needs to import create app and I need to create my application bar invoke by invoking the invoking the application factory and probably flake eight it's not gonna like new this time the real order did not restart so I started by hand just in case let's see and there we go so now we every step of the way I make sure I make sure that the application continue to work and now we have a fairly good in my opinion structure with a blueprint for the API a models package that has each model in its own sub a models package with each model in its own module and also any additional database specific utilities like like this class that I'm using in this application also in their own sub module and and there we go that is all it took and not a single time I had problems with circular dependencies by following the good practice of not not putting the inputs at the top but putting them in the place where you basically will you remove the code that you're moving to the second to do the other module so anyway I thought I could keep going I don't think I'm going to because I I don't think I have anything new to show but if if I wanted to keep going what I would do is I would make this API a sub package instead of a sub module so the same thing that I did with models where where I move models of Pi into the models package and renamed it dunder init I will do the same thing API folder and then move API PI into it as standard in it and then start breaking up from from there hey we got a question okay so so yeah I think I'm going to stop if you have any questions if there's anything that I didn't cover please let me know or better yet right right the question and then I'll go ahead and answer it but yeah it looks like this isn't going to take a lot of time because there's only one question okay so what do I think I'm gonna switch to full screen what do you think about flask restful extensions so I'm okay with them I'm not sure if you mean specifically the extension that's named flask restful or if you're talking in general as you know in terms of you know the the few extensions that are out there that that work for that help create api's so what I prefer these days is to write my API directly in flash I don't find what the these extensions do that useful to be honest so for example speaking specifically about flask restful so the the things that are nice that flask restful does one thing is that it can validate your your payloads when the client sends something it basically gives define a schema for your resource and then the extension validates it for you and that that's a great feature but I prefer to use marshmallow which is a standalone library that does that and that's it really well so so so basically I use flask and then I import marshmallow standalone there's not even a flask extension for it and and that's how I how I validate my payloads and with everything else that these extensions do I always find a little bit easier for me to just import a Python package that helps with area and not basically get a single single extension that basically made the choice for me of you know which which validation package I should use and and so on so so yeah I'm I'm fine with them I even I I blogged about Flash graceful specifically in the past because I at at some point I used it but but yeah these days I don't really see a need to to use an extension so anyway that's my point of view but but I have nothing wrong to say about those extensions so next question at what point do you decide your application is large enough to be worth breaking up as you've done yeah that's a good question so if I find myself scrolling up and down through a through a large file trying to find something then that's a good indication you can go by a number of lines and some people impose a limit on number of lines per module I don't do that myself but really I just you know I sort of it becomes a nuisance for me to to navigate the file and that's that's the point where I say okay I had it I mean I'm gonna go break this up and and oh you know all the steps that I did today I you know just for the sake of the demonstration I did them all one after another but I don't really do that when I do it for real when I do it for real but basically I make each step like the ones I showed today I've made just one and then I'll keep going and then eventually again I start finding that I need to to do one more thing and and then I keep migrating my applications that way and that works because I always have my tests I have tests that I can use to make sure that I'm not breaking anything and that's the reason why doing all this this type of surgery on your project is okay it basically relies on having a good test set that you can you can use make sure that you're not breaking stuff yeah I think that that's all I can say about that I don't really have a rule of thumb it's just when when it bugs me to work with a large file I break it so okay and we'll have one more question which library do you use to handle JSON web tokens so the the one that you use is PI JWT actually I don't even know any others I'm sure there are some but but yeah I've been using pi JWT I believe there's a flask extension for it that may be a flux flask extension that wraps by JWT I've never used the flask extension I don't think there's a need you know what part of me liking flask is that you know it's it's a minimalistic framework and for that reason even though there are cases where a flask extension makes sense there are many other cases where you know really a flask extension does not really have a lot to to the normal you know the standalone package so I think PI GWT is one of those examples it's pretty good it's also very simple and yeah I've never tried I don't even know you know what what other things the flask extension can do because I always import PI JWT you know on its own and one more question would be possible to have a webcast on testing in flasks like how you use talks today yeah sure definitely that's actually that that would be a good topic so what I was thinking for from the next month so one I haven't decided yet but one that I was thinking an interesting topic was to show how to use flasks with an IDE so today you saw me that I used or actually I don't know if you I don't think I mentioned this let me switch back to my screen so this this thing that I'm using here is Visual Studio code and I refrain myself from from using the IDE features of this application Visual Studio code is actually pretty good it's a pretty good IDE it supports Python natively and you can do a lot of things without leaving the IDE like for example or all these things that I did in the terminal you could do them from a panel here in this in this application I decided not to because I wanted to make sure this this demo was accessible to everyone regardless of the tools that you use I didn't want to be seen as you know you have to use Visual Studio code because I don't think you have to but what I was thinking a good topic would be would be to show how to use flask and specifically how to run how to run the application that the flash grant command which is tricky when you use an IDE and I was thinking that the two that I was gonna demonstrate where we're gonna be we should pseudocode and pycharm so that that's one topic that I was considering and then the other topic that was considering is going over the new features that came with flask 1.0 the the flask 100 release from from what was it a month ago or so so those two and and I think yeah doing one on unit testing will be interesting as well so those are the three options at some point I'm going to decide which which one of the three but but definitely I'll get to the three of them in time so let's go back here and okay looks like there are no more questions yes they are no this is a chat okay so yeah there are no more questions so I guess we're done for today I hope that this was useful as a demo on how to break the application if you try this with your own application and have problems let me know I'm always interested in finding what what people find difficult definitely the takeaway for me from today is that I need to investigate why there are why there are errors that flask does not report when when every loads I for some reason I didn't notice that of course you can tell that this was you know I didn't practice a lot I I mean I I just came here and started breaking up this app like like I do you know many apps but but yeah I didn't notice that that this I'm thinking might be flask one the diversion one of flask which I'm using today that has a problem with reporting errors when you know sometimes the first I don't even know why some were reported and some or not I need to I need to find that out so this was good for me I guess because I have now a bug to chase as well in in flask I noticed that most big applications these days like YouTube or Facebook are in the form of a pie why I don't understand what that means sorry yeah I don't understand that question if you have five seconds to explain it better by submitting a new question if not yeah I don't know we can take it offline if you want to explain better so going once going twice and it went okay so thank you very much for for joining me today I am going to be working on new content so I I recommend that you keep an eye on courses bigger brain but calm because yeah I'm hoping at some point I'm gonna I'm gonna drop some new stuff there okay sorry okay so the question was that I noticed that most big applications these days like YouTube or Facebook are in the form of api's how do you go about writing a streaming API like YouTube to be utilized by a mobile app well you use so I guess as an example I can refer you to my I wrote a couple of blog posts on streaming video and that works with mobile as well so I mean if you want to learn how to how to use the streaming streaming support in flask that that would be a good way so look up in my blog the video streaming articles there's two and you should probably read them in order that was one that I made maybe two three years ago and then an update that I made are not too long ago and once you learn the technique then you don't have to use it for for video you can use it for other things for example something that I do that I don't think I've ever showed is I if you need to run a command in the server then I stream the output of that command to the web browser so you can you can start a command from from the browser and then watch the output of the command in real time in your browser and that that's also done with streaming so so yeah yeah I I've written about that so there's definitely something that that's something that flask can do very well okay thank you very much for joining me and I guess we'll see you in about a month and look for a Twitter announcement when when I know the the final date for this so thank you very much
Info
Channel: Miguel Grinberg
Views: 11,965
Rating: 4.9310346 out of 5
Keywords: python, flask, web development
Id: NH-8oLHUyDc
Channel Id: undefined
Length: 68min 57sec (4137 seconds)
Published: Sat May 26 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.