SlideShare une entreprise Scribd logo
1  sur  39
Télécharger pour lire hors ligne
What is wrong with
API wrappers and
how can we do
better
FILIPE XIMENES
@xima
Recife
Recife
http://www.vinta.com.br
API
Application Programming
Interface
What???
◇ APIs define the interaction interface of a
software.
◇ software might mean:
○ a Python class
○ a database
○ some hardware
○ some plugin
○ a library
○ a web service
Eg.: Python class
class User(object):
name = ''
email = ''
def update_data(self, name, email):
self.name = name
self.email = email
def talk(self, message):
print('{} says: {}'.format(self.name, message))
Eg.: web service
GET /v1/media/000000
HOST: https://api.instagram.com
POST /v1/media/000000/comments
HOST: https://api.instagram.com
DELETE /v1/media/000000/comment/111111
HOST: https://api.instagram.com
Integrating web
services
I want to retrieve basic user data
after he logs in using his
facebook account.
Our options
◇ Option 1
○ Read Facebook's API documentation.
○ Use Python's urllib2 to make requests.
◇ Option 2
○ Read Facebook's API documentation.
○ Use Requests lib to make requests
◇ Option 3
○ Search for an open source lib with ready to
go python methods for making endpoint
requests.
○ Go to the beach.
Web API libs, aka web API
wrappers
◇ What is it?
○ Implementation of a web API documentation
using a programming language.
◇ What is it for?
○ Creates a layer over HTTP using your favorite
programming language
■ authentication
■ composing urls
■ prepare requests
■ process responses
■ format data
facepy
facepy
from facepy import GraphAPI
graph = GraphAPI(oauth_access_token)
my_links = graph.get(path='me/links', page=True)
for link in my_links:
print(link) # link is a dict
facepy
graph = GraphAPI(oauth_access_token)
endpoint = '{}/{}'.format(user_id, 'statuses')
data = ??
user_data = graph.post(endpoint, **data)
Some notes
◇ Need to study facepy's documentation
○ Request interfaces
○ Parameter passing
○ Response access
○ Exception treatment
◇ Need to study Facebook's documentation
○ Endpoints and HTTP methods available
○ Parameters for each endpoint
○ Data formatting for each request or response
python-twitter
python-twitter
import twitter
api = twitter.Api(consumer_key='consumer_key',
consumer_secret='consumer_secret',
access_token_key='access_token',
access_token_secret='access_token_secret')
statuses = api.GetUserTimeline(
user_id=user_uid, count=20,
since_id=id_of_first_tweet)
python-twitter
python-twitter
Some notes
◇ pydoc documentation
◇ Not very pythonic code
◇ No pagination support
◇ A method for each endpoint
◇ Models instead of dictionaries
I need a system that monitors
Twitter, Facebook, Instagram,
Blogger and Tumblr, to capture
posts from each one of my users.
The ideal wrapper
◇ Authentication
◇ Requests as the engine of requests
◇ Pagination support (generators)
◇ Exception raising according to error codes (403,
500...)
◇ Hypermedia support (links, HATEOAS)
◇ Explorable
◇ Simple documentation
Tapioca Wrapper
Delicious and comes in
many flavours!
tapioca-wrapper
https://github.com/vintasoftware/tapioca-wrapper
What's tapioca-
wrapper?
Python framework to create
web API wrappers
Demo time!!
tapioca-facebook
Congratulations
you now know how to use ANY
tapioca wrapper
Developing a
tapioca wrapper
The code
Python
https://github.com/vintasoftware/tapioca-
facebook/blob/master/tapioca_facebook/tapioca_fac
ebook.py
Endpoint mapping
https://github.com/vintasoftware/tapioca-
facebook/blob/master/tapioca_facebook/resource_
mapping.py
tapioca wrapper features
◇ A method for each endpoint
◇ Explorable
◇ Requests lib
◇ Pagination support
◇ Hypermedia support
◇ Quick documentation access
~250 lines of code
tapioca-facebook
~1,000 lines of code
facepy
~6,000 lines of code
python-twitter
~150 lines of code
tapioca-twitter
1 hour
tapioca-parse
Notes
◇ We still need to read the API
documentation but not the wrapper
documentation.
◇ Fun to explore the package.
◇ Writing new flavours:
○ Almost 100% declarative.
○ Few lines of code.
○ Batteries included.
◇ There's a lot more to improve.
QUESTIONS?
@xima
github.com/filipeximenes
ximenes@vinta.com.br
www.vinta.com.br

Contenu connexe

En vedette

Business plan presentation
Business plan presentationBusiness plan presentation
Business plan presentation2AM
 
Plastic Recycling Business Plan Presentation
Plastic Recycling Business Plan PresentationPlastic Recycling Business Plan Presentation
Plastic Recycling Business Plan PresentationAnkur Verma
 
Plastic Manufacturing Company - Business Plan
Plastic Manufacturing Company - Business PlanPlastic Manufacturing Company - Business Plan
Plastic Manufacturing Company - Business PlanAyush Man Tamrakar
 
Parle-g marketing strategy
Parle-g marketing strategyParle-g marketing strategy
Parle-g marketing strategyDhruv Patar
 
Project on marketing study of parle
Project on marketing study of parleProject on marketing study of parle
Project on marketing study of parlePayal Awere
 
15 Business Plan On Plastics Recycling
15 Business Plan On Plastics Recycling15 Business Plan On Plastics Recycling
15 Business Plan On Plastics RecyclingDr. Trilok Kumar Jain
 

En vedette (8)

Parle g ppt(1)
Parle g ppt(1)Parle g ppt(1)
Parle g ppt(1)
 
Business plan presentation
Business plan presentationBusiness plan presentation
Business plan presentation
 
Plastic Recycling Business Plan Presentation
Plastic Recycling Business Plan PresentationPlastic Recycling Business Plan Presentation
Plastic Recycling Business Plan Presentation
 
Plastic recycling
Plastic recyclingPlastic recycling
Plastic recycling
 
Plastic Manufacturing Company - Business Plan
Plastic Manufacturing Company - Business PlanPlastic Manufacturing Company - Business Plan
Plastic Manufacturing Company - Business Plan
 
Parle-g marketing strategy
Parle-g marketing strategyParle-g marketing strategy
Parle-g marketing strategy
 
Project on marketing study of parle
Project on marketing study of parleProject on marketing study of parle
Project on marketing study of parle
 
15 Business Plan On Plastics Recycling
15 Business Plan On Plastics Recycling15 Business Plan On Plastics Recycling
15 Business Plan On Plastics Recycling
 

Plus de Filipe Ximenes

Multitenant applications: How and Why
Multitenant applications: How and WhyMultitenant applications: How and Why
Multitenant applications: How and WhyFilipe Ximenes
 
Tasks: you gotta know how to run them
Tasks: you gotta know how to run themTasks: you gotta know how to run them
Tasks: you gotta know how to run themFilipe Ximenes
 
[Quase] Tudo que você precisa saber sobre tarefas assíncronas
[Quase] Tudo que você precisa saber sobre  tarefas assíncronas[Quase] Tudo que você precisa saber sobre  tarefas assíncronas
[Quase] Tudo que você precisa saber sobre tarefas assíncronasFilipe Ximenes
 
O que é esse tal de rest? [PyBR2016]
O que é esse tal de rest? [PyBR2016]O que é esse tal de rest? [PyBR2016]
O que é esse tal de rest? [PyBR2016]Filipe Ximenes
 
APIs: o que são? onde vivem? do que se alimentam? [PyNE2016]
APIs: o que são? onde vivem? do que se alimentam? [PyNE2016]APIs: o que são? onde vivem? do que se alimentam? [PyNE2016]
APIs: o que são? onde vivem? do que se alimentam? [PyNE2016]Filipe Ximenes
 
Usando tapioca para acessar APIs web [PyBR11]
Usando tapioca para acessar APIs web [PyBR11]Usando tapioca para acessar APIs web [PyBR11]
Usando tapioca para acessar APIs web [PyBR11]Filipe Ximenes
 
Expressões idiomáticas do python
Expressões idiomáticas do pythonExpressões idiomáticas do python
Expressões idiomáticas do pythonFilipe Ximenes
 
Boas práticas de django
Boas práticas de djangoBoas práticas de django
Boas práticas de djangoFilipe Ximenes
 
Migrando do App Engine para o Heroku
Migrando do App Engine para o HerokuMigrando do App Engine para o Heroku
Migrando do App Engine para o HerokuFilipe Ximenes
 

Plus de Filipe Ximenes (9)

Multitenant applications: How and Why
Multitenant applications: How and WhyMultitenant applications: How and Why
Multitenant applications: How and Why
 
Tasks: you gotta know how to run them
Tasks: you gotta know how to run themTasks: you gotta know how to run them
Tasks: you gotta know how to run them
 
[Quase] Tudo que você precisa saber sobre tarefas assíncronas
[Quase] Tudo que você precisa saber sobre  tarefas assíncronas[Quase] Tudo que você precisa saber sobre  tarefas assíncronas
[Quase] Tudo que você precisa saber sobre tarefas assíncronas
 
O que é esse tal de rest? [PyBR2016]
O que é esse tal de rest? [PyBR2016]O que é esse tal de rest? [PyBR2016]
O que é esse tal de rest? [PyBR2016]
 
APIs: o que são? onde vivem? do que se alimentam? [PyNE2016]
APIs: o que são? onde vivem? do que se alimentam? [PyNE2016]APIs: o que são? onde vivem? do que se alimentam? [PyNE2016]
APIs: o que são? onde vivem? do que se alimentam? [PyNE2016]
 
Usando tapioca para acessar APIs web [PyBR11]
Usando tapioca para acessar APIs web [PyBR11]Usando tapioca para acessar APIs web [PyBR11]
Usando tapioca para acessar APIs web [PyBR11]
 
Expressões idiomáticas do python
Expressões idiomáticas do pythonExpressões idiomáticas do python
Expressões idiomáticas do python
 
Boas práticas de django
Boas práticas de djangoBoas práticas de django
Boas práticas de django
 
Migrando do App Engine para o Heroku
Migrando do App Engine para o HerokuMigrando do App Engine para o Heroku
Migrando do App Engine para o Heroku
 

Dernier

FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 

Dernier (20)

FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 

What's wrong with api wrappers and how can we do better [EP 2015]