 Nice introduction, nice introduction. All right. So, hello everyone, full room. So, thank you very much for attending So yeah, my name is Felipe Ximenez and This is my Twitter account so you can find me and I'm from Brazil so I'm actually from this city called Recife and quite far so long trip and I'm glad I'm here so and Thank you all for for coming All right, so I'll work and I have a company there. It's called Vinta and We do web development. So we work with a lot of APIs. We work a lot of Integrate integration with external services such as Twitter Facebook Instagram and Some private services We do a lot of Angular we do a lot of react. So Yeah, so if you need something like this just talk to me All right. So Here I'll be talking today about APIs. So API is just an acronym for application programming interface with which does not say a lot about what it is But it gives an idea. So it's basically an API defines how We interact with a software and when I say a software like it can be a Python class a database Some library or a web service or or any plug-in. So It's pretty broad definition. So for example, if you are talking about Python And we have this user class the API will be It will have like the attributes the name and the email and we have the methods update data and talk So this would be the API of my user class For example, if you go to a web service and API can be this is like the API for Instagram So the first method gets a media it can be a photo or video the second method posts a comment And the last one deletes it. So this is a Partial definition of the API for Instagram. All right So I'll be talking more about integrating services So we are focusing here about web APIs, all right So let's say a Customer comes to you and he asks you to develop a software web software Whatever and he wants the user to log in with Facebook and then He wants you to fetch like his the user basic info from his Facebook account So I have some options here for what we can do the first option will be go to Facebook documentation and read its API documentation and We could use you all lead to That comes with Python to make the request that would work. No problems second option would be again read the API documentation and Instead of using you are a leap to we could use request library, which is much more cleaner and I really like it it's easy to use and this would be easier and and it's a good option to and The third option would be go on Google and just search for like wrappers and Something ready to go to interact with Facebook and then we could go to the beach That's like I suppose we could let's take a deeper look to see if this really possible so first of all first of all So we are on the same page when I say API wrapper I'm Rapper would be just a Implementation of API documentation in a programming language and it can be in programming language Today we will be talking about Python, but you can be a wrapper for the for web API on any language So it's basically just a thin layer over HTTP and It will help you developing software Integrating services. So some things that are basic to a to a API wrapper is authentication It should be able to compose URLs. It should be able to prepare requests before you you actually make them and Should be able to process responses and format data. All right, so If you are talking with the API that returns JSON, it should be able to convert JSON to a native Format, so if you're talking Python that will be probably a dictionary So for example for this task, we could use Facebook. That's one of the most popular wrappers for Facebook API available and it's basically composed of two methods the first one is the get method and you can pass a path and some options We can see on the example here We are building the endpoint on the path So I have to like write this string for the endpoint and then I can pass like page true and this will when I fetch This endpoint me links it will return for me Not all the links in my Facebook wall It will turn pages of it because you said that it would be too much data to come come at once So we said Facebook returns it on pages So when I pass past page to face by it will iterate when I iterate over the response face by will automatically fetch new pages So I don't have like to worry about getting the next space and the next page So I would just work with the links. It returns also They return the links. They are dictionary. So they are Python dictionary, right? So the next max method is the post and this time We again have the to build the endpoint like a string But now we don't know since the post we are trying to post In this example, we're trying to post a new status to my Facebook wall I don't really know what's the format of the data the expecting neither the documentation tells me So I'll have to go to a Facebook's documentation API documentation and read about this so our first We are we first thought we could just get like this wrapper from the internet and started using it Without reading documentation and when you get it, you just see it's not possible You have you still have to go to the documentation so Some notes just said so we had had to read about the wrapper documentation. We had to read about the API documentation as well So another example would be Python Twitter. That's one of the most popular wrappers for Twitter. So It's a bit different from the face by one. It's instead of me building the you are the endpoints it gives me the methods so I can just pass parameters and It will handle the the rest for me Here are some some of the methods of this library As we can see it does not follow spepo pep8. So it's using combo case instead snake case nothing wrong with this just not usual and Instead of returning dictionaries it returns classes. So a bit different as well All right, it also use spy documentation. It's accurately not very Pythonic It has no pagination support. So I cannot do what I just explained to you about the face by one and And it has a method for each endpoint and uses models instead of dictionaries. So Okay, given the scenario, let's imagine now And this is a real scenario. We actually happened in my company a client came to us asking to force to integrate with Facebook Instagram Twitter Tumblr and blogger. This is a lot of integrations and imagine now I'm having to always read the wrappers documentation and then the API documentation. It's it's a pain. It's really painful so Let's think of if you are trying to write like the the perfect Rapper API wrapper what would you like to have it in it? So authentication? That's basic. Oh wrappers should have it I would like to use requests as I said, I really like this library it should have pagination support and Should would be nice to have like some exception raising. So I know what error code came on the response Right hypermedia support would be also be nice. So I could just follow links instead of building this these links I'd love to be it to be explorable So I can play with it before doing the final implementation And I would love to have a simple documentation. So Since I will have to read the the API documentation anyway I'd like the wrapper documentation to be simple. So I don't waste too much time on it and This brings us to tapioca so First what's tapioca? All right So tapioca is this Brazilian food. It looks like a teela. It's a bit softer And you like you put whatever you want inside it. It can be sweet. It can be cheese. It can be a chocolate. It can be Meat whatever you want. It's really tasteful if you ever come to Brazil You should try it So I have a little demo for this So that's me preparing a tapioca now back to the code so you can find this library at My company's github so vinter software slash tapioca dash wrapper and What is it it's basically a Python framework for creating web API Rappers so talks ship Let's show me the code demo time Let's see what we can do with tapioca All right, so We'll be using tapioca Facebook. So that's the tapioca implementation for the Facebook API and we also be using I Python so we can better explore the package and It has some nice features when you use I Python. So first of all, right, let's go I Python and All right import the library from tapioca Facebook import Facebook so All right, it's slow, but yeah So first thing we have to pass an access code access token so we can use the API We will get this from the developers dot Facebook dot com you on the graph API Explorer. So Just grab it Value token nice back to the right Nice so All right, let's play the first thing I like to go it's if you if you press tab on I Python you can see the full list of methods available for this wrapper and we'll be looking at the user likes method and We are like learning about this right now. So let's see what's available at the user likes endpoint so we can see there's a Partially mounted URL if you will go with a question mark you can see more info about it And that's from the package. So I can see I can pass an ID to the URL and Let's but this does not give like full information about this endpoint. So let's Open the documentation for this endpoint so you can understand more about it So you can just go open docs and you open your browser straight away All right, so we can see though. They'll be returning a data and a page in a data is an array and This that this data has this response will have will come in pages as we saw and These are the available attributes for the response so Yeah, all right, so we just just took a look at the Directly at the IPA documentation as you wish Oops something happened some problem here. Okay back to the code. So So now we'll be making the request so API user likes and I pass I'll pass the ID The ID will be me. So I'm getting the likes for my pace with my Facebook wall page And now I can see The URL is filled. So likes will show instead of ID will show me it just fill it the URL for me nice and now we actually do the request so response equals likes dot get Nice so response now it's filled with the likes we can see it and There are all my light all the first page for likes on my Facebook We'll be looking at the name of the likes so the the pages. I like it and You can see there's a page in and a cursor and a next URL. So we are exploring it So we are looking at a name if you come back to the API documentation We can see the the response actually has a name. So let's play with it All right, so Let's get like the first like I have in on my on the response so the data has a Array and I am accessing the first site in and I'm getting the name. So pretty straightforward. You just use Just navigate for it like it's a Python object And again, you can see the page in let's try to like to get the next page the URL for the next page of results so this time responses paging and next and We can see the URL and we can also fetch it. So Response page next and dot get so as you can see it's pretty pretty straightforward for forward to Fetch new stuff if you ever have a link you can just get it. It's pretty straightforward All right, so Now let's let's do some Let's print all the all the old pages. I like on Facebook So I can just go within for liking response and print the the name of each page so Tapioca will be Itterate over it and and whenever you reach the fin the end of a page will fetch more data That's automatic. So I don't have to worry about paging. It goes Right away. So that's all my bikes and You can see there's like little breaks. So this is the the library fetching more data Sorry All right, so yeah As you can see I recorded a video I was too afraid of like doing it right now, so So like let's try now to play with my photos, all right so this time we'll be using the user photos endpoint and I will pass in me again as the ID of this endpoint and get it and Now I would like This is the results and now I'd like like to to get the first picture. I have you know my wall so be data the first item and then source All right So this is the link for the image and let's try to open it on a browser So again straight forward forward So open in browser and we can see the picture on the browser and you can do this with any link you want So this is our local Python user group a lot of people nice and To end let's just try to post something on my Facebook wall so it's time API user feed and Now this instead of using get will again will pass in me because I'm posting to my wall and I'll be posting the using the The same interface as the request lead has so data and I can pass a dictionary of the Information it and it will convert to JSON and send to Facebook. So the message will be Posting to my Facebook wall using tapioca Right, let's see live on on my page now. This is the return. So return an ID for the for the post I made So if I go to my profile Yeah, that's me See it just post on my wall. So it did work Nice. So that's all for now. Let's get back to the presentation So Congratulations, it's just you don't know how to use any tapioca library So once you you learn how to use one type of tapioca library You are now able to play with any other. So if you get a tapioca Twitter, you already know how to play with it It's just the same as we showed on the Facebook one and Let me show you how easy is to write a wrapper for any service you want. So This is an example for the Facebook one. Okay, let me leave this Let me go full screen and This is all the code I needed to write the wrapper I just play with so it's for a line of lines of Python. It's pretty straightforward and not very difficult The rest will be just Resource mapping so it's pretty much a big dictionary with information about endpoints and how to fill them and That's how it's so Just like a documentation that it's not like real code. So So these are our things that comes with any tapioca wrapper They have a method for each endpoint They are extremely Explorable as we saw on the on the demo. They use request leads to make requests So if you know requests, you already know how to play with tapioca library They have pagination support and that comes for free. It has hyper media support. So you can follow links that's also for free and You can access documentation pretty easily. So It's nice. You don't have like to know everything before you start coding. You can just Redocumentation as you go. So some benchmarking the tapioca Facebook library has 250 lines of code and The face by one has a thousand so one fourth the size and Again, this includes the resource in mapping the dictionary I show you so it's not actually You don't feel like writing code. You just feel like documenting it For the Twitter one it the difference much bigger The tapioca Twitter has 150 lines of code and the Python Twitter has six thousand so huge difference And for example, it took me one hour to write the full wrapper for the parse dot-con service So it's pretty quick All right, so some notes about the project again We are we are instead of having to read wrappers documentation and API documentation will be now reading just API documentation because we're we already know how to use the wrapper It's fun to explore. So it's we are you are encouraged to play with the wrapper before you actually do the final implementation and Writing new flavors new tapioca flavors. It's pretty easy It's all almost a hundred percent of the clarity is you have few very few lines of codes and and comes with batteries included so Nice and To finish that's there's a lot to improve it. It's a new project. I've been working on it for about six months and If you have some ideas and you have like something you'd like to add to it You're very welcome. There are a lot of things. I still want to add it to it They are listed on the github page of the project. You can go there and give your opinions and Yeah, thank you You have any questions? Great talk. I wanted to know How flexible it is working with because the the API's are used Facebook and Twitter They're pretty restful in like a HTTP restful style. How well does tapioca work with API's? That don't really conform to restful standards. Is there much flexibility for plugging into those as well? Yeah, sure. I mean It doesn't matter What API it is it will use like it will probably it should use the basic HTTP methods so get post-delete options and since it Use the same HTTP methods. You are able to write a Tapioca for it It may not look like as good as the Restful API look, but yeah, you still can't do it It's possible Any other questions? All right. Thank you for a talk. Do we have any Already any implementation to manage different API versions for one endpoint for example Facebook has I've seen a 2.2, but there's a 2.4 and some things are different sure all right, so This is to be I Mean defined how how we work, but my first idea for this would be have Different libraries with different versions. So if you want the Facebook one one dot zero Version you find typioca Facebook one dot zero and we find the two you could tapioca Facebook two dot zero but I mean I'm open to two new ideas if I had some just tell me Thank you for the talk. I just wanted to check which versions of Python that's the Poco support It goes from two dot seven to three dot four So yeah, I don't think I'm bad bow Hi, I wanted to ask you how does tapioca integrate with the asynchronous frameworks? For example, if I use an asynchronous library like tornado or a sync IO How would it integrate because the default client would block on Request, is it possible to make the call is synchronous? Again, if you have some ideas just tell me and we can think of something Okay, so but Now it doesn't support this Any other questions What are the IPs are supported besides the Facebook and Twitter now, right? So right now we have Facebook Twitter Parts.com Mandrill There's some water. I don't remember now, but like This is also nice. If you had if you want to to implement a new one, please come to me and I'll help you I mean, it's all open source if you want to do it on your own just do it But if you have any any doubts just come to me and I have I will help you writing specific implementation for for services Or questions. All right. I think that's it. Thank you very much