My PyCon 2015 Sessions
Posted byon under
In this short blog post I want to share the two presentations I gave at PyCon 2015, which are now available to watch on YouTube.
Flask Workshop Tutorial
The first presentation is titled "Flask Workshop", and is a 3 hour long beginner's introduction to the Flask micro-framework. Here is the link to the video:
You can download the slides for this presentation here.
Is Your REST API RESTful?
I gave my second presentation on the first day of the main conference. This was an extremely difficult personal time, as just a few hours before on that same day I gave this talk my wife called to tell me that my mother had passed away. It felt really good to give this presentation though, because I know she was proud of her little boy, who gets to travel to cool places to talk about what he does.
This is a 45 minute long presentation where I explain what REST APIs are, along with a live demonstration. Here is the video:
The slides for this presentation are here.
As I'm sure you understand, I had to cut my PyCon plans short and return home the next morning, so I was unable to participate in many events of what was looking to be another great conference. I want to thank all who approached me to offer their support.
If you have any questions about these presentations, feel free to write them below.
Become a Patron!
Hello, and thank you for visiting my blog! If you enjoyed this article, please consider supporting my work on this blog on Patreon!
#1 Anton Antonov said 2015-04-13T17:42:16Z
Amazing presentations. Especially the REST one. It's an eye-opener and it really shows many flaws in popular services' REST APIs, especially the HATEOAS part.
Honestly, the only REST API closest to HATEOAS was Github's - https://api.github.com/ and it's still not nearly as good as the one you showed.
Also, I'm sorry for your loss. I admire your courage and strength to carry out the presentation despite the unfortunate turn of events. Stay strong and keep teaching us more.
#2 Dietmar said 2015-04-17T22:55:07Z
I am very sorry for your loss. Many thanks for all the great tutorials!
#3 Liang Gao said 2015-04-18T00:57:39Z
Filtering resource collection works very well!
But I found a problem when I decorate the route with marshal_with, it will return the OrderDict instead of query object. So I had to do something like that to get over it
#4 Miguel Grinberg said 2015-04-19T03:00:11Z
@Liang: I haven't tested how the collection decorator works with Flask-RESTful. I don't know what changes you've made to your collection decorator, but my original version will probably not work as you coded it, since the return value is a Python dictionary with the data, not a query that you can execute by calling all().
I honestly find the pluggable views in Flask and Flask-RESTful difficult to work with when using decorators, I prefer the plain old view functions. I encapsulate my resources at the module level instead of at the class level.
#5 mohamd ali said 2015-04-28T18:19:45Z
God knows I did. The respect you
And allow me to get out of the subject and tell you a little thought in the religion of Islam
This is what I love for myself. Therefore I advise you to do
Because death is close to us all.
#6 Leo said 2015-05-22T21:01:40Z
Great blog! I've found your blog very helpful learning Flask!!! And I'm very thankful by that...
I wanna make you a question: how do I get the "http" cli command? I've being using curl and it's a little pain in the #$%$#. ;-)
#7 Miguel Grinberg said 2015-05-23T23:22:47Z
@Leo: the "http" command line client is called "httpie". It is a Python package, you can install it with pip: "pip install httpie".
#8 VD said 2015-06-28T20:16:33Z
Is there an introduction for Pyramid devs trying to move on to Flask? Does your book maybe serve this purpose?
#9 Miguel Grinberg said 2015-07-01T19:13:44Z
@VD: You don't need instructions tailored specifically to the framework you know to pick up Flask, the general tutorial/book/videos should give you what you need.
#10 Haris Sumair said 2015-08-04T14:58:46Z
I love the way you use Git!
The incremental versions :)
That's a really nice way of teaching things.
#11 Kyle Lawlor said 2015-08-19T17:07:19Z
I recently purchased your Flask book and I think that it is excellent.
I am learning a lot as I work through it.
Thank you for putting so much effort in to the material.
I plan to watch these videos soon!
#12 Peter HIRT said 2015-10-20T15:54:34Z
many thanks for all this learning material on Flask: really appreciated!!
I would like to do production Machine Learning (the prediction part to be more precise) with an app where I submit the object features as JSON object to a Python based server, launch the predictor part and get back a JSON object with the classifier or whatever I am trying to get. I am thinking Flask to be the right environment to be the server. The actual web app, I would do with Angular and running out of a different server (I like Angular ;-). What is your recommendation to me on this? Is this good for significant type of traffic? Are there any tutorials out there where I can get inspired on how to embed a Python script with the model (incl scikit-learn etc.)?
#13 Miguel Grinberg said 2015-10-22T05:23:55Z
@Peter: Flask is definitely a good choice for an API based on your description. As far as Flask is concerned you can import and use any packages or libraries that you need, so you can just import your prediction code and use it like you use it on non-web apps. I would separate the API from the actual work, maybe by putting the ML part in a Celery worker. This will allow your API to not block when it starts one of these prediction jobs. The article on Celery here on my blog will show you how you can work with asynchronous tasks.
#14 Gaurav said 2015-12-06T10:25:40Z
Hi, I really liked you presentation on the Rest API, especialy the hyper media part, I think this should be strictly followed as this would greatly help the advent of IOT.
After watching this presentation I did some research and found this http://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/#create-post_lists_list_id_members
this is the api for mailchimp, I think It follows all the 6 conditions described and would help the future readers who want some real world examples of hypermedia implementation
#15 Jonathan said 2016-02-29T11:21:55Z
En primer lugar siento la perdida de tu madre. Te acompaño en el sentimiento. En relación con tu charla, como todo el material que generas, simplemente genial. Para los que estamos aprendiendo es un material de un valor incalculable.
En mi proyecto personal actual estoy construyendo una API REST para mi afición (radioafición) en la que un servicio de radio interactua con la informática para tener una base de datos de usuarios. El proyecto es una especie de CRUD con esteroides :)
Por favor, sigue así de educativo y toda la ayuda e información sobre el desarrollo de APIs es mas que bienvenida.
Un abrazo desde España.
#16 Carl said 2016-06-14T05:18:30Z
Do you have an example of using PATCH in a RESTful API with Flask? There seems to be a special way using JSON Pointers to handle PATCH requests. Should I Just stick with PUT instead?
#17 Miguel Grinberg said 2016-06-15T14:40:22Z
@Carl: PATCH isn't as well defined as PUT. For PUT, the accepted practice is to require a complete resource representation in the body. If you want to support partially updating a resource, then PATCH seems to be preferred. I have implemented partial updated with PUT many times, so I won't point your finger at you if you do that. I recently started using PATCH though. I think a nice specification that includes the use of PATCH is JSON-API. See http://jsonapi.org.
#18 Hara Gopal said 2017-08-15T03:34:21Z
this is a simple question and i hope you will answer. from your videos/books (paid/free), there was one simple concept in flask_login that i was not able to understand clearly and also couldn't find the the answer else where...
@login_manager.user_loader<h2>"The user loader callback function receives a user identifier as a Unicode string. The return value...."</h2>
in this whole concept involving UserMixin/decorator/login_user() method, i failed to understand which one feeds which. here are my questions...
1) where does the load_user function under the decorator gets the user_id/identifier from ?
2) does it come from the login_user function we define in the route ?
3) if you have to put these three (UserMixin, decorator, login_user() in sequence, one providing input to the other, what would that sequence be ?
Thank you in advance
#19 Miguel Grinberg said 2017-08-15T21:53:54Z
@Hara: Yes, this can be confusing. Let's assume the user is already logged in. When the user clicks on a link to go to another page, these are the events that occur:
- the server receives the new request, which includes the Flask session cookie in it
- Flask dispatches the request to the proper view function
- The first reference made to Flask-Login's current_user triggers a _get_user function defined by Flask-Login to be called (current_user is not a "real" variable, it works more like a property in that its value is generated by calling a function).
- The _get_user() function from Flask-Login obtains the id of the logged in user from the user session. This id was placed there by the login_user() call made when the user logged in.
- Then _get_user() calls the functions registered with the @User_loader decorator and passes the id to it. The return value of this function is then assigned to the current_user variable and returned to the caller.
A small variant of the above occurs when the @login_required decorator is used, instead of referencing current_user explicitly. But this is really very similar, because the implementation of the login_required decorator, in fact, is the one that references the current_user proxy variable.
Hope this helps!
#20 zhuhuiac said 2017-09-14T09:16:08Z
Hi Miguel, thanks for your tutorial, I learned much from it. But I have a question, when I register in your "api-pycon2015", I found there is no error warning when I use a taken name. Are you intentional?
#21 Miguel Grinberg said 2017-09-14T23:11:09Z
@zhuhuiac: Looks like that was an omission.