00:00 you think of Python web microframes, Flask is definitely near the top of the list. With almost 19,000 stars on GitHub, it's a powerful and extensible web framework. It even powers the bandwidth intensive audio delivery of the Talk Python To Me podcast. In this episode, number 48, we'll talk with Miguel Grinberg who has written some amazing Flask tutorials, books, and open source projects! This is episode number 48, recorded February 2nd 2016.
00:00 ERROR: [music]
00:00 to Talk Python to Me. A weekly podcast on Python, the language, the libraries, the ecosystem, and the personalities.
00:00 is your host, Michael Kennedy, follow me on twitter where I'm @mkennedy
00:00 up with the show and listen to past episodes at talkpython.fm and follow the show on twitter via @talkpython.
00:00 episode is brought to you by Hired and Snap CI. Thank them for supporting the show on twitter via @Hired_HQ and @snap_ci.
00:00 have a couple items for you before we get to Miguel.
00:00 Miguel has generously agreed to give away an ebook copy of his Flask Web Development published by O'Reilly. To be eligible just become a friend of the show at talkpython.fm
00:00 been two weeks since the kickstarter to launch my Python online training adventure. I have a few updates you might be interested in.
00:00 project is funded and well under way. The kickstarter is over $14,000 and going strong. I launched a new website: training.talkpython.fm. Check it out, you can see the next set of classes I'm working after the kickstarter closes. Just click courses in the nav bar.
00:00 again, thanks to everyone who backed the project so far. If you want to get access to my course Python Jumpstart by Building 10 Apps for over half off at $29 hurry over to talkpython.fm/course and back the kickstarter before it closes in two weeks.
00:00 let's get onto an excellent conversation with Miguel.
02:25 Miguel, welcome to the show.
02:26 Thank you. I'm glad to be here.
02:27 You have a lot of stuff going on, this is going to be a fun conversation.
02:30 I hope so. I'll try to make it fun.
02:32 Yeah. We are going to focus this around Flask, and look at all the different things you have going on, kind of in that space, yeah?
02:38 Sounds good.
02:41 Ok, cool, now before we get into the details, let's talk about how you guys started in programming, Python all that stuff, what's your story?
02:49 Yeah, so I first got into programming in the probably mid eighties, 1980s, with the TI 99 computer, you can Google it if you don't know what that is, but it used to be a very cool computer at the age where computers were really 3:04 and most people didn't have them, in their homes, and I started writing games in Basic, on TI99 computer. Eventually, that seemed slow so I decided to learn the second language you can program on that machine, that was assembly language and I started writing games in assembly.
03:22 My Gosh, so you tool like a real easy sort of gentle introduction to game programming, yeah?
03:29 Yeah, those were the two steps you had on the TI machine.
03:33 That is a big step!
03:34 Yeah, that one 3:33 thing. And Basic was slow, that was the other choice, right. We needed the speed, assembly was the answer, so yeah, I wrote a Tron lifecycle 3:44 game on Assembly language, on a TI99 computer.
03:49 That's cool. Did you release it_
03:51 I released it to friends only, so yeah, not commercially.
03:57 Yeah, I mean, it basically predates the web, so what do you release it to, in some sense, BBS maybe, right?
04:02 Right. There were BBSs in those days, right.
04:06 That may be aging us.
04:07 I think I can still tell the actual connection speed based i=on the sound the motro made when it connected.
04:13 [laugh] So my first pps speed was 1200, and you could put an age to me, by knowing that, right?
04:26 Yeah, I'm just a little younger, I came in the 9600 days.
04:28 Yeah, I am old.
04:30 Ok, so you got into Basic and then assemble, and then, where did it go from there?
04:36 So, and then, this was when I was a teenager, so before college, so then, in college I learned the languages you normally learn in college, Pascal, C, C++, Smalltalk. Basically, i got a job- so I am from Argentina and one of the things that's great about college in Argentina is like you can do it at night, and work full time, or you study so I was lucky to have found a job, a programming job, form the early days in my college time, I had basically both sides, the academic side and the having to do something production wise, having to get something that works and that makes money all at the same time, so it was pretty good.
05:20 Yeah, that was a good opportunity to have a chance to write a professional code or whatever you want to think of it, as a student, because a lot of people come out of college and they are like, now let have try to go find some experience so I can get a job, right, which is kind of a tough place to be.
05:33 Right. So, thanks to the TI99 I had some experience I could get a job without having a college degree so those two complemented and allowed me to have a full experience form early on in my life. So, then Python came much later, maybe 8, 9 years ago, I was working in a company where we had a really large C++ codebase that was really painful to test, this codebase was expose as DLL C++ API on Windows, so I decided to create a Python wrapper so that the testers could write tests more efficiently-
06:14 Right, they didn't have to write it in C++ and all that stuff, right?
06:18 Exactly, right, and compile it, and test it, and crash and then do it all over again. Right, so I decided to create a Python wrapper and basically, I got hooked, I really liked it, so I started from there.
06:29 Interesting. So so you are working in C++ and you made these wrappers, and I guess the thought process went something like why don't I just keep working over here, why do I have to go back to those compilers and headers and libs and all that stuff, right?
06:40 Right, so exactly, and the same way I studied and worked, at the same time, when I am working, even now, I always have lots of side projects that I do just for fun, so at those times, you know, 8, 9 years ago, doing stuff on the web seemed to be the right thing.
06:58 Yeah, excellent.
06:59 Ok, so what can I do with Python, for the web, you know, that led to well, you guessed it- Flask.
07:05 Yeah, so you have a lot of going on with Flask, why did you picked Flask, over the other options, and you know, given the time there might have been well, there were not many other choices, but Django was probably out at that point, yeah?
07:14 Django was there, Bottle was there, believe it or not. I did look at Bottle, at that time, so basically this was a funny story- I started, it was sort of friendly competition with my wife, my wife who is not a technical person, she was blogging and she was having pretty good success with her blog, and she was always teasing me that she was doing something technical and I was behind. I had to basically start blogging, that was the dare that she put in front of me. So I said, if I am going to blog, I am going to blog on my terms, so I had to write my blog engine. Right, I am not going to use Wordpress or one of those.
07:54 No, that has PHP in it.
07:54 Exactly, right, so went and looked at Django, and Django seemed over7:58 for a little blog that I wanted to write, and I looked at bottle and Bottle seemed too little, there were some things like writing more than one file, it was unclear how you would do it, you would have to start inventing things, so I settled with Flask. Flask was right in the middle, and it seemed like the right balance.
08:15 Yeah, I think you know, I think finding that balance sort of depends on your experience, how you like to code, how much hand holding do you like in some sense, right, like I personally love to write my HTML just so and my CSS and have lots of control over the URLs and everything, so these micro frameworks like Flask and Pyramid, I am a huge fan of.
08:39 Yes, I completely agree with that. I micro manage my code, I really like to write myself, and be aware of everything that's going on, make it very clear, make it very me. Yeah, Flask seemed to be the right balance of not having to deal with all the pain of HTTP, Request, 8:56 responses, and you know, Flask abstracts you form dealing with that but at the same time, it doesn't handhold me and I can do what I want which was a requirement for me.
09:07 We had Armin Ronacher on show I think it was 13, one of the earlier shows and sort of dug down into a lot of the pieces of Flask, but maybe, you know, that's a long time ago, maybe you could get people like a high level look into just what the moving parts of Flask are, and kind of like how much work is it to get a website up and running?
09:25 Right. There isn't really much. Flask is very small, you can go read the code and you will probably understand most of it, in your first read, it's super clear code, it's code that I could write, the kind of code that I wish I could write actually, because it's so clear. And, basically, the main thing the Flask does for you is to abstract you form the interface with a web server. You don't have to think about parsing HTTP requests, or formatting the responses, basically you get a decorator, that allows you to associate a function that you have to write with an HTTP request. That's basically pretty much the big thing that Flask has for web development. And then, you 10:11 your application, you supposedly need to know to write it.
10:14 Right, sure, so 10:15 like the "Hello world" app on Flask is probably 5, 8 lines.
10:20 I think it's 7 lines if I remember correctly.
10:23 7 lines, yeah.
10:27 Yes, so you have 7 lines, 4 of which are boiler plate, so your typical Flask boiler plate is 4 lines, 4 lines of code and then you write your functions, you write typically 1 per HTPN point that you want to support, and in the function you do any processing you need to do and then, return your response, which usually is if you are doing a web application, is a string containing HTML that you can generate yourself or through a template engine.
10:56 Right, and the default is Jinja 2, right?
10:58 Jinja 2 comes with Flask, it doesn't need to really, you can use any template you want and this is theme with Flask, for any x feature you can use any package that does X, Flask really doesn't care much about the stack that you use. So yes, Jinja comes integrated there is a very light integration and that helps you with generating the HTML, so if you write your HTML in files and put placeholders for the dynamic components and then you generate those, dynamic parts in your function logic.
11:33 Right, and do you pass just like a dictionary off to the-
11:36 Correct, yes. And then, Jinja 2 that's the replacement.
11:39 Yeah, and then the View11:40 in general put it together right?
11:42 Yeah. So, really for a beginner, being able to get the hello world thing, we put 7 lines and then start hacking it and make it do more things, most beginners can get it right away, which is fantastic, right?
11:55 Yeah, it is quite easy. I am also a fan of Pyramid. I like Pyramid a lot, but that step form 0 to kind of "I've got something I am ready to start working with," is much bigger, than it is in Flask, I think to a large degree because of the packaging, you've got to kind of deploy or setup your website as a package.
12:14 Right, honestly, I see Pyramid more closer to Django than to Flask.
12:21 Yeah, yeah, I agree. I think Flask is much smaller but I think one of the like the sort of super powers of Flask is it's super small, but there is so many things you can plug into it. Including a number of your open source projects, right?
12:35 Yes, I have written a number of things that you can have to Flask which are all optional and then that's a big thing, right, in Flask as I said before, you pick your components, so yes, I've written stuff to the web sockets, in Flask, that's actually one that my most popular extension so that you can do web socket and it does it in a way that is very Flask friendly, not the typical web socket thing that you see, but the web socket connection is represented by a function that runs forever, or at least through the life of the connection, and in this extension that I built you handle events and these are short events that are built on top of the socket IO protocol.
13:18 Yeah, ok, very cool.
13:17 So, it has good side and a bad side. The good side is that if you are familiar with HTTP route, it'e very easy for you to start doing web socket, because with this extension, you do it more or less the same way. The bad side is that you know, they are not the same. So a lot of people get confused about it, they think that they can do whatever that they can do with http requests, and the fact that the extension makes it simple, doesn't mean that you do have Request context which you don't when you do web sockets, right.
13:49 Right, interesting. So that is something I wanted to ask you about while we are still down in the details of Flask and so on, and frameworks like Pyramid, they will pass a request object, that has the request, the response, the headers, all that kind of stuff, into your view methods, or if you are using Pyramid handlers, it will pass it to your class, you store it for later, those kinds of things. Flask doesn't do that, it uses these sort of contexts that are ambient to your code and those are really cool, can you talk about that a bit, maybe how that works?
14:17 I can. So this is possibly the only aspect of Flask that can be thought of somewhat magical, it's only magical because a lot of people do not understand them, once you understand it, of course, there is no magic. But yes, the idea is that if Flask didn't do what it does with the Request all checks and other variables, that are Request specific, you will have for each of your handle14:41 functions, you will have to receive a bunch of arguments. The Request and then you need to 14:47 response but then you may need the session, and sometimes you don't need them. So, the way Flask handles that is that it makes those available as context variables. They are present in every Request you don't get them as argument, you see them as global variables, and Is aid they are magical even though they look like global variables, they are not, they are really thread specific global variables, so if you have a production web server running multiple threads, each thread would see look at this for example the request global variable, and it will see a different one, it will see the one that applies to that thread. That's a little bit magic, that a lot of people get confused about, but other than that, basically you know that when you get into a request handler, you have access to the request as a variable call request, you have the session as a variable called session, there is a couple more and then extensions can have more things using the same idea. So for example, if you use Flask-
15:44 Do they maybe just pile on top of the same pieces?
15:45 Yes. They use the same-
15:49 Like that shared global context?
15:50 Correct. So for example, Flask login which is an extension to do authentication, it has a current user, so you know that's always there, if you are in a Request. I think it's a very clean way to have the things out of the way, if you don't need them and then hand16:04 when you do. I really like that, I enjoy not having those as arguments in my functions.
16:11 Yeah, that's definitely nice and clean, that's cool. So, let's take a moment and talk about your blog. So, you said it starts by you writing your own blog engine, because you are not going to be ruled by one of these pre-built ones, right?
16:24 Correct, yeah, that's not my way. So I wrote the engine, and you know, ok, so I am done, I have a blog now, and my wife would still say, "Well, you are not blogging," so I had to start writing.
16:38 It doesn't matter if it runs, there has to be a post on it, right?
16:40 Right. So right there with the Flask experience of building the blog in my mind, what made more sense was to blog about Flask. So, I started writing articles about writing a complete application, you know, using Flask, and that was how this mega tutorial was born, this is a 17 part very detailed Flask tutorial, it's starting to age a little bit, it's been written I started maybe 4 years ago, and I wrote it during period of a year a half, so yeah, that basically coves a buns of areas, for example I am pretty proud that I have very good coverage for internationalization, not very many people talk about, so you can learn how to do that with Flask Ajax, which is more common now as single page apps. That was basically source of not only a way to teach what I learned, but also to for myself, to learn because it pushed me to learn more things, I wanted to do something more- I didn't want it to look as I said Flask beginner, which I was at the time.
17:46 Yeah, that is so true. At the time, but then you go through teaching this stuff and like, well, if I am going to talk about this, I got to know all the little details, and maybe if you are going to write an app, you might only learn just enough to get that app working. But if you are going to try to teach it, you've got to dig deeper.
18:02 Exactly, I always say that teaching is the best way to learn.
18:04 Yeah. It absolutely is.
18:07 I learn by teaching.
18:08 Yeah, I think one of the ways I think of it, sort of conceptualize it, is if you are a say a consultant, and you went to work at a place and they say, "You need to solve this problem." If you know one way to solve that problem, that's probably good enough, right, you are ready for your job. But, if you are going to go teach other people and there happens to be 3 ways to solve it, not only do you need to know the 3 ways, you need to know when to use which, what are the tradeoffs, all that- like, those are the kind of details you would just not bother with unless you have to each it- that's great.
18:08 ERROR: [music]
18:08 episode is brought to you by Hired. Hired is a two-sided, curated marketplace that connects the world's knowledge workers to the best opportunities.
18:08 offer you receive has salary and equity presented right up front and you can view the offers to accept or reject them before you even talk to the company.
18:08 candidates receive 5 or more offers in just the first week and there are no obligations ever.
18:08 awesome, doesn't it? Well did I mention the signing bonus? Everyone who accepts a job from Hired gets a $2,000 signing bonus. And, as Talk Python listeners, it get's way sweeter! Use the link hired.com/talkpythontome and Hired will double the signing bonus to $4,000!
18:08 is knocking, visit hired.com/talkpythontome and answer the call.
18:08 ERROR: [music]
19:35 At the time at work, stealing the C++ we were trying to do some things with rest APIs, also get an interest sort of in parallel when I got tired of writing mega tutorial articles, I would take a vacation form that and write about rest.
19:51 Right, so you basically have 2 really really large areas on your blog and one is this Flask tutorial, and that would be a good place for- f y listeners are out there and like, "Hey, I am getting into Python, maybe web apps are cool, maybe Flask is cool, how should I get started, your tutorial is a good place?"
20:05 I think it's a good place, there are a warnings in the proper places in the tutorial where things got a little bit out of date, I will give you just one example, back then I though using Open ID for authentication was a cool idea, so Oauth was-
20:21 We were told Open ID was cool, we were told.
20:22 Yes, we were told. And of course, today, it's kind of an old thing. One day I am probably going to go refresh that portion of the article, that chapter. But yeah, right now, you can still implement it but of course, if you are doing anything for real you will not do what I did back then.
20:41 Sure, you could say, you could log at Open ID and your users would say, "What's OpenID?"
20:46 Exactly. Right, probably there is one or two providers that still support it. And, you know, it's decreasing very quickly, so yeah.
20:54 Ok, cool, so the Flask tutorial sounds great and then the other thing you focused on a lot was Rest APIs, yeah?
21:01 Yeah, this was mind blowing when I learned about Rest, it seemed great and I said, "Why didn't I think of this?" It seemed like a very clear way to organize and do the separation of concerns between the client and the server. And write more 21:17 client applications. I really made an effort to learn if you Googled Rest, you are going to find there is a lot of discussions about what is Restfull and what's not Restfull, people who are very angry at others, because they are calling something Rest and they thing it's not. You know...
21:36 So, let me see if I got it right, if I have a service, like a website and returns something, so if it returns like Json over HTTP it's a Rest service, right?
21:47 Just kidding. [laugh]
21:48 Oh, you are teasing.
21:51 I am going to start some kind of Rest-afarian war.
21:56 So, the Rest ideas are great, but even if you read the paper by Roy Fielding, it seems like he is saying simple things but you know, hidden behind those very sparce wars, there very complex ideas that you usually have think and make sure you understand. I did try to get to the bottom of it, I am really not one of the angry people who think that you should call Rest, things are 100% pure Rest, I think Rest has ideas that are very good, even if you implement some of them you are still winning and I am not going to complain if you call it rest.
22:34 Yeah, absolutely, I think that Rest as a black and white concept, was much stronger several years ago and now people see it as a spectrum and they are like you know, let's adopt HTTP, Json sort of APIs, so we can talk about iPhones, web apps and other just it's almost a practical drive to adopt something like Rest.
22:57 Yeah, I think it's a collection of ideas and some ideas are very easy to grasp and almost everybody say, yeah, this is great, the idea of having resources, right, everybody gets that and how to use git post, and delete, that makes perfect sense. So, almost everybody get that. But, if you start thinking about hyper media for example, which I think it has only 5 or 6 words int he original paper by Fielding, it's like it's mentioned in Passing23:25 right, I mean, not everybody will almost nobody get what you gain by implementing hyper media. And, for many projects, it doesn't make sense, but for some it does. So, I wanted to understand even if I do not always agree that it is a great idea, I wanted to understand what it meant and what you could do, and I even did one of my PyCon talks, the one I did last year, I showed you know, a fully implemented hyper media enabled rest API which was pretty fun project to do, another way that forced me to learn something to keep learning, I had to implement that in a way that the few hundred people that were there and then the people who watch it on YouTube won't point fingers at me saying that's wrong.
24:10 Yeah,t hat's cool. And I have seen that talk, that was a good one and the title is "Is your rest API restful" which I think is a clever title, right?
24:19 Right, yeah, I mean it plays on this continuously ongoing discussion between the people who want pure Rest we call Rest and you know, the people who say ok, it's a rest API whatever, they didn't implement all the items in the list, but it's still Rest.
24:35 Yeah, so one of the principles at Rest is to sort of embrace the HTTP-ness of the transport, right like you said use the verbs and the URIs and all those kinds of things, right?
24:42 This is very interesting, because if you go read the paper the Fielding paper, he almost briefly mentions HTTP and the message there is that you could implement Rest over other transports, so if you go by that document, there is nothing that says that you should use get requests for this or that because that's HTTP specific. When you go and implement Rest, you are supposed to map the ideas of Rest into the transport that you are using. So, all these rules that say that you should use-
25:22 I think part of the reason that HTTP gets so tied up with the rest, is it's the only practical choice for a broad reach, on the internet.
25:32 That's correct. So, to my knowledge, nobody is doing Rest over something that is not HTTP, I am sort of a little bit disappointed that Fielding or one of his colleagues didn't write something more specific to HTTP. Because I think that's the source of all the confusion, it's that mapping how you map what Fielding said in that original paper, to the HTTP protocol which allows you to do the same thing in many different ways, in a lot of cases.
26:04 Right, yeah, it's unfortunate, I think you even mentioned this in your talk, that there is not like a reference implementation client server that you could go look at, right?
26:11 Right, and then there is one, because really, it's very difficult to make something that complies with every little thing that is mentioned in the original Rest documentation, right, and some things, you have to do the mapping, right, so they are not clearly specified so that you can find out how to implement that with HTTP. So yeah, it's very interesting how the technology developed around it, and I think Rest took off, because at least some part of it, as I said before, are very easy to grasp, and they are very powerful.
26:41 Right, and if you look at the alternatives, they were like xml soap, web services with WS star specifications making it even more complicated and all that kind of stuff, right?
26:51 Right, it's like, yeah, I mean, you have boiler plate and you need to learn a lot of things and you get the same thing that goes on with Flask, Flask you can pick up really quickly and Rest at least a portion of it, you can pick up really quickly too.
27:03 Yeah, I think Rest is one of the things you can pick up quickly, but it takes a long time to master it.
27:08 Yes, if you want it to get all the advantages of Rest, definitely it takes a long time, I hope I did a good job on that talk because I really tried to explain in a very simple language what each of these six app characteristics of Res mean and how they benefit you-
27:23 I was still waiting for a picture on stateless.
27:26 Because you had pictures, you were like, this one I can't do in a picture, it's stateless, what does that look like?
27:30 I started with the idea of making pictures for everything, but, yeah, I know. It would have been pretty hard to do stateless, yeah.
27:39 Yeah, well I didn't have an idea.
27:41 But there was- the pictures in some of them, they do help drive the point home, I mean, especially cashing and those things you normally don't think about.
27:51 And, they are kind of important, I think they are important, especially if you are doing something big, right, if you are doing a Rest API for controlling your garage door, on a Raspberry Pi, and you probably don't care about cashing. But, if you are getting paid to do a Rest API you should probably care about it.
28:09 Yeah, you definitely should. So, all of these posts and articles sort of led you to your next endeavour, which was your book, right? So, you wrote all these articles and O'Reilly reached out to you and said, "Hey, that sounds cool, you can write a book."
28:22 That's actually pretty much how it went, yeah. This editor from O'Reilly, she was basically looking for a Python content, and she ended up on my blog, at the time. At some point she came to Portland for a conference and we met, and basically after that meeting, yeah, she said, "Well, send a proposal, we really like to have a book on Flask."
28:48 Nice. And I looked through it so much, I haven't made it all the way through, but I really liked it, I think it has a really nice practical style, it's not too verbose, it doesn't go into too many details, but it doesn't feel like you are skipping over so much, I think it's a really nice book, do you maybe want to kind of talk about the theme and you have this one kind of major app that you built up throughout this book, right?
29:09 Yeah, so it is probably a typical book for learning framework, I decided to write it in kind of like tutorial way, basically each chapter builds on the previous one and by the end of the book, you have a complete application which is sort of a Twitter kind of clone and I decided to do it that way because people learn- in my experience, it is easier to learn gradually, and if each chapter starts with a new project, you have you lose your context, so you have to sort of start over. Doing it that way also allowed me to do something that I think it's also very original, which is how I have the code for the book on GitHub, people tell me I am crazy because it's a lot of work but basically what I did is I engineered the history using 30:03 bases I engineered the history of the repository to be one commit per hit point basically, there are few in each chapter, but each time you reach a point where you can go test something, there is a commit there, if I need to make a fix, I need to insert it into right place in the history so it's- I developed a few tools to help me with that so that I don't make mistakes. Because it's crazy, I agree, I am kind of crazy.
30:29 Well, it's really cool from my reader perspective, so basically, you start out the book saying, look, you need to know Git, welcome to the 21st century and you are programmer so you've got to know Git, and here is how you get the code, right, you check this out, you check out the repository but then you go tags, right, that are basically safe points?
30:49 Correct. Yeah, so you have spread through the book at any point where you are ready to try something, it tells you ok now you will get tag 7a, they are named with the chapter number and then a letter, and so you get that, and if you want to see what changed from the previous tag, you can do a dif, which is awesome, even on the GitHub a website, you can dif one commit and see exactly that these are pretty small incremental changes so if you want to find out how I did authentication for example you find a commit that does it and if it against the previous one and you see all the changes not just the big stuff, every little thing, including template changes, every little detail is there, so if you want to learn with a lot of detail what you need to do to add that feature, you can find it in the dif.
31:36 Yeah. I think it's really nice way to do it and sort of having a zip file with chapter 1, chapter 2, chapter 3 in it, right.
31:44 Right. I started that way, it seemed wrong and it's also difficult to maintain, so you know, over all, people criticize the book some people did, so far, in the almost two years it's been out, nobody criticized the Git organization, right, the repository with the code.
32:00 People like i, they seem to like it a lot.
32:06 Yeah, yeah, that's really cool. So, you know, as far as I made it, I really liked the book. It's tough to do stuff in public, out on the internet and other places like you can't please everybody, so you just do the best you can, right?
32:16 Exactly. I mean, it's ok when it resonates with some people, and it's not going to with some others, and that's fine, and these days, I mean, back in those days, this was the only book, but now, it's not the only book, there like 5 or 6 or 7. There is plenty of choice, it's a great ecosystem.
32:34 Yeah, that is a great ecosystem. So, your work on your blog led to your book, your work on your book led to some videos that you did, right, so as these things go you do some minor thing and they just snowballs over time if you keep at it in the ways you don't expect maybe, right?
32:55 Yeah, in the ways I did not expect, that's actually true. The book went out, did really well, so O'Reilly was super happy with it. And, they asked me to do a webcast which I did a couple, but then I said well maybe we should do more Flask content, so they asked me to think about if I wanted to do a video tutorial, basically, a video version of the book. It's kind of actually boring for me, to do it all over again, you know, in a video.
33:29 Yeah, sure.
33:29 Instead, I decided to think about what else could I do in video format, so one thing that some people found the book was too easy, and some people found that the book was too hard, right, both sets of people were right, right-
33:44 It's a relative statement, that's right.
33:45 I decided to write a introductory Flask course on video, which studied at much lower- the book is kind of for intermediate, you need to know your way in Python, to really take advantage of it, so this is much more basic and in the video, you can see my screen as I do the exercises. For a lot of people, the beginners find the visual component very inviting, right, that's how they avoid messing up. If they are reading it form the book, they don't see my terminal, they don't know what I type so seeing, the very basic steps to build a web application being played in front of them, I thought it was a good idea.
34:26 Yeah, I think these video tutorials where you are doing screen sharing and especially when people are new they can watch, I think it's really, I feel almost like the blood pressure goes down, the stress goes down, it's just like this thing that seemed hard, I saw like I built it up and I saw all the steps, none of them were hard, none of them were confusing, started form here, went to there, and I can do that, why did I think this was hard, but of course if you are like running through the docs and you don't know where to start, it's a whole different type of thing, so that sounds really cool, really helpful.
34:26 ERROR: [music]
34:26 is a continuous delivery tool form Thoughtworks that lets you reliably test and deploy your code through a multistage pipelines in the cloud, without the hasle of managing hardware. Automate, and visualize your deployments with ease and make pushing to production an effortless item on your to do list. Snap also supports Docker and in browser debugging, and they integrate with AWS and Heroku.
34:26 SnapCI for sponsoring this episode by trying them with no obligation for 30 days by going snap.ci/talkpython
34:26 ERROR: [music]
35:51 That was video 1.
35:53 That was video 1, complete beginner with only a little experience in Python you will do that, that would be the basis, you will know how to write simple applications with Flask and then you can go to the book, hopefully at that time the book will make sense, if it didn't before, and then the second video that I did was specifically on Rest APIs, and this is because when I was writing the book, I was in a constant fight with my O'Reilly- friendly fight, I should say, she is awesome, but constant fight regarding page count, they wanted a relatively smallish book, and I tend to put a lot of detail, I want to make sure the things are clear so I write a lot, so one of the things that suffered in the book was the chapter on Rest APIs, it's much smaller than I thought it should be. So, I decided to expand on that, on the video and because I wanted it also to be fun for me, that video has also APIs for Raspberry Pi so I have my Pi on screen, showing you cool stuff you can do with the camera, it was a blast to do it. I enjoyed it very much.
36:56 That's really cool. It's tough when you are starting out or you are teaching people who are starting out to make something that's interesting and engaging, and so, if you are going to do things like that, like grab the Raspberry Pi and like show how you are controlling the camera and like even though the code might not be super complex, it feels like you are learning more than just a loop or print statement or something.
37:15 Right, you are bringing up the good point, I don't think that video is for advanced users, it's probably still intermediate level, but it is dedicated to Rest APIs, I think there is a lot more to say about APIs then what you get form the book, so it was a good thing and being able to show how to implement APIs on devices, like the Raspberry Pi I think that was great and that would be something more difficult to do in book format, I think, I mean especially playing with the camera, in part of the video I show how to do it time lapse, there is an API to trigger time lapse, so I have the camera pointed at myself doing the course, and then I play the time lapse, you know, it's pretty cool, it was really fun.
37:58 Yeah, really nice, really nice. So, we have time for a few more questions, one thing I did want to talk to you about while we were together is your open source projects, but I kind of feel like maybe the way to do is to give people a sense of what you've done, what's out there and maybe some other time we'll come talk in depth about them.
38:18 Yeah, sure.
38:20 I'll say one of your projects and you give me like the elevator pitch- one to two sentences like what is this. How does that work?
38:26 It sounds great.
38:27 All right. Flask socket IO.
38:28 I briefly mentioned it before, it allows you to do web socket applications with Flask, it makes that super easy.
38:35 All right, that's the continuously running function with events.
38:37 Great. And then Flask Migrate?
38:40 Flask Migrate, allows you to do data base migrations, using alembic, which is the migration engine for SQLAlchemy, so this extension makes it very easy to implement migrations in Flask.
38:52 Ok, interesting. I have to check that out. Flask HTTP Auth?
38:55 For rest APIs to do authentication. Again, decorator base-
39:00 Like OAuth kind of stuff?
39:00 This is OAuth, this is a basic and digest authentication for an API, let's say you don't have a web application so you cannot do OAuth which requires the web, so implement token based authentication for example, this will give you decorators that basically prevent you form having to deal with the headers 100%, so you can do everything in python land.
39:26 Right, you could do it yourself but why would you want to, right?
39:31 Yeah, Python socket IO?
39:32 Python socket IO is one of my two non Flask specific projects, this is the engine to Flask socket IO the one that I mentioned before, so Python socket IO is a general purpose socket IO server so you could do socket applications for any framework or just a plain no framework, just a socket IO server. Since we are talking about it, would like invite anyone who wishes to write a wrapper for other frameworks, I maintain the one for Flask, but if there is anyone interested in supporting Python socket IO in Django, Pyramid, Bottle, whatever else, I will be more than happy to help.
40:11 I see, so that would be the core-
40:13 That's the core, correct.
40:14 That you would use to build that and not have to basically maintain it, yeah?
40:17 Yeah. It has no relation with Flask.
40:20 Ok, awesome.
40:19 It's Python pure framework.
40:21 Sure. Ok, Flask moment?
40:49 Yeah, that's really nice, and moment Js is live, right, so like if it said 5 seconds ago, then let's say six, seven, and so on, is that right?
40:55 Yeah. It's awesome, yes, The way I implement it is optional, you can request not to do that for some things it doesn't make sense, but this extension will allow you to do that if you want to say keep updating, you send refresh equals true, in the template, and that's all it takes, yeah, and then it updates on its own.
41:11 Yeah. That's really cool. So you render the page, you look at it and it says 30 seconds go grab a coffee, then it says 2,5 minutes ago, right, it's beautiful.
41:21 Yeah, it changes, it's really nice.
41:23 Yeah, Flask page down?
42:03 Yeah, ok, yeah that's really cool. It's coming to a climax with the open source projects, the last one is actually called Climax. [laugh]
42:10 Climax is- this was a really fun one, implemented like in a weekend, two weeks ago, to be honest. So, I really like Click, Armin Ronacher's command line, decorator based command line parser, but there is one thing that I don't like-
42:27 Yeah, it's cool and we talked about that on his show when he was on, we talked about his work with click, so...
42:32 Right, so another one of those things that I think damn, I should have thought of that, I hate the guy because he thought of it, [laugh] but anyway, one thing that I don't like is Armin's distaste of argparse, right, he doesn't like argparse, and for some things that I am doing, it would be useful for me to be able to integrate with existing applications that use argparse, so i created Climax as a clone, it's a blatant copy of Armin's Click, but as engine, it uses argparse. So that allows you, for example, you could take a tool like say alembic, which uses an argparse or its command line, and import it into a bigger command, that you own, and offer you know, Alembic's set of options as a sub-command, because it nicely integrates and you can compose bigger parsers by taking argparse parsers from different sources.
43:27 Ok, that is really cool. Very nice. Ok, so I‘ll try to have links to all that stuff and everything else we talked to on the episode page.
43:36 Cool, so let me ask you two more questions before we wrap it up. So, last week or two weeks ago you wrote Climax, what editor did you use to write it?
43:48 I used Vim with the Python mode plugin. That's my always go to editor I am going to be honest, I know probably I will say 5 to 6 keys in Vim, and it makes me super proactive, even though I know very little about it, I don't use any of the advanced things, but Python mode makes it really cool, I also like PyCharm, when I need to debug something really complex, I tend to go to PyCharm, but more for the debugger than the editor.
44:17 Yeah, ok, cool. Yeah, the debugger is pretty sweet. So, the other question is there is 60 000 packages on PyPi, what ones would you recommend people check out that maybe they haven't heard of, so you know, they probably heard of Request, maybe Flask, but you know, what else should people go check out that is maybe not well known yet that you want to tell them about?
44:38 One package that I really like speaking of debuggers, I started my career working on Windows, long ago, so I am used to Visual Studio and the Visual Studio debugger which is really good, so I am used to interactive debugging more than GDB, so there is a package called PUDB, I am not sure how popular it is, this is an interactive debugger but it works in text mode, so you are debugging something on a remote server or maybe on an AWS instance, something that you can only get through s shell, you can pop this thing, so pip install PUDB and then it works like PDB the command line, Python debugger but it brings up a GUI text mode GUI and it's really decent, to work and it runs anywhere, right, because it's text. I go to that debugger a lot when I am debugging a remote sites, it's extremely useful.
45:33 Yeah, that is cool, you are SSH-ed somewhere there you go, right, you don't want to install, there is no way really to reasonably install PyCharm out there anyway, right, so-
45:41 Right, exactly, you can't, so there is a word for that, I mean, you might be able to set up a remote debugging, but it's a hassle, if you need to debug something-
45:48 Yeah, exactly.
45:49 Just put the PUDB package and you know, you are good to go. It's super easy to use.
45:54 Yeah. Ok, good recommendation. All right, so I guess people should go check out your book, check out your blog, what else they would be up to now, they have heard all about what you are up to?
46:07 They are definitely invited to contact me, to interact, tweet me questions, I spend a lot of time answering questions whether it's stack overflow, or twitter, comments on my blog, probably I spend on average I would say an hour a day, responding to questions and I enjoy that, that's another motivation for me to learn and stay current on things. I would like to be engaged and so I invite everyone to send me questions, problems, ideas... We'll all learn together.
46:39 Awesome. Very cool. PyCon this year is coming to Portland- Your hometown, my hometown.
46:49 I love that.
46:51 Are you going to make it?
46:52 Yes, definitely. I have my ticket. I am going to be there, I think I sent 4 proposals, so we'll see what happens, I hope I get to talk.
47:01 Excellent, god luck with that.
47:01 I've been doing tutorials, the last two PyCons, and this year I am doing I guess an advanced tutorial, I hope I get it, it's to address the question that there is a common misconception that Flask does not scale.
47:12 Interesting. Ok.
47:13 I created a tutorial dedicated specifically to address all those concerns and show how to scale Flask, in 3 hours.
47:21 All right, that sounds really cool. Like a really good follow on two other ones, so that will be great, I'll see you in Portland. Thanks for being on the show.
47:27 Yeah, it was a pleasure. Thank you for inviting me.
47:27 has been another episode of Talk Python To Me.
47:27 guest was Miguel Grinberg and this episode has been sponsored by Hired and SnapCI. Thank you guys for supporting the show!
47:27 wants to help you find your next big thing. Visit hired.com/talkpythontome to get 5 or more offers with salary and equity right up front and a special listener signing bonus of $4,000 USD.
47:27 CI is modern continuous integration and delivery. Build, test, and deploy your code directly from github, all in your browser with debugging, docker, and parallelism included. Try them for free at snap.ci/talkpython
47:27 check out the video course I'm building. The kickstarter is open until March 18th and you'll find all the details at talkpython.fm/course.
47:27 can find the links from the show at talkpython.fm/episodes/show/48
47:27 sure to subscribe to the show. Open your favorite podcatcher and search for Python. We should be right at the top. You can also find the iTunes and direct RSS feeds in the footer on the website.
47:27 theme music is Developers Developers Developers by Cory Smith, who goes by Smixx. You can hear the entire song on our website.
47:27 is your host, Michael Kennedy. Thanks for listening!
47:27 take us out of here.