SlideShare a Scribd company logo
Consuming
your APIs with
Python
Michael Petychakis, Ntua
{
"@context":{
"schema":"http://schema.org/",
"as":"http://www.w3.org/ns/activitystreams#"
},
"@type": "schema:Person",
"schema:name": "Michael Petychakis",
"schema:jobTitle": "Phd Student",
"schema:telephone": "(425) 123-4567",
"schema:email":"mpetyx@epu.ntua.gr",
"schema:url": "http://www.mpetyx.com",
"schema:nationality":"Greece",
"as:actor":{
"@id":"http://www.twitter.com/mpetyx"
}
}
About @mpetyx
Consuming APIs with Python
Consuming APIs with Python
Consuming APIs with Python
Consuming APIs with Python
958 million websites
60 trillion
web pages
Each API is Unique
http://www.slideshare.net/busaco/presentatio
ns
http://www.imdb.com/title/tt0401383/
http://www.last.fm/music/Moby
http://vimeo.com/channels/731014
Name each resource by using URLs
+optional parameters
(useful for pagination, partial responses,
filtering,…)
/snakes?limit=3&offset=14
/snakes?fields=name,age,description
Design accepted representations to be sent
by potential clients
consider existing standardized data formats
e.g., HTML, Atom, JSON,…
Accept: application/json (Digg)
/venue.json (Foursquare)
http://api.sciencemuseum.org.uk/exhibitions/
?output=json
Choose the representation(s) of the
response to be sent to client
https://github.com/mpetyx/apimeetup
“Clone” the code
# Step one for every Python app that
talks over the web.
$ pip install requests
Requirements
import requests
resp = requests.get('http://apiathens.herokuapp.com/tasks/')
if resp.status_code != 200:
# This means something went wrong.
raise ApiError('GET /tasks/ {}'.format(resp.status_code))
for todo_item in resp.json():
print('{} {}'.format(todo_item['id'],todo_item[title]))
GET /Tasks
task = {"summary": "Take out trash", "description": "" }
resp =
requests.post('http://apiathens.herokuapp.com/tasks/',
json=task)
if resp.status_code != 201:
raise ApiError('POST /tasks/
{}'.format(resp.status_code))
print('Created task. ID: {}'.format(resp.json()["id"]))
POST /Task
# todo.py
def get_tasks():
pass
def describe_task(task_id):
pass
def add_task(summary, description=""):
pass
def task_done(task_id):
pass
def update_task(task_id, summary, description):
pass
#todo.py
def _url(path):
return 'http://apiathens.herokuapp.com' + path
Helper Function
import requests
def get_tasks():
return requests.get(_url('/tasks/'))
def describe_task(task_id):
return requests.get(_url('/tasks/{:d}/'.format(task_id)))
def add_task(summary, description=""):
return requests.post(_url('/tasks/'), json={
'summary': summary,
'description': description,
})
def task_done(task_id):
return requests.delete(_url('/tasks/{:d}/'.format(task_id)))
def update_task(task_id, summary, description):
url = _url('/tasks/{:d}/'.format(task_id))
return requests.put(url, json={
'summary': summary,
'description': description,})
Integrated Code
import todo
resp = todo.add_task("Take out trash")
if resp.status_code != 201:
raise ApiError('Cannot create task: {}'.format(resp.status_code))
print('Created task. ID: {}'.format(resp.json()["id"]))
resp = todo.get_tasks()
if resp.status_code != 200:
raise ApiError('Cannot fetch all tasks: {}'.format(resp.status_code))
for todo_item in resp.json():
print('{} {}'.format(todo_item['id'], todo_item[title]))
Let’s Use our Library!
Thank you
Michael Petychakis
@mpetyx
<a
href="mailto:mpetyx@epu.ntua.gr?Subject=
Hello" target="_top">Drop me an e-mail</a>

More Related Content

PPTX
Hydra: A Vocabulary for Hypermedia-Driven Web APIs
PPTX
Kringla.nu: linking and presenting linked data
PPTX
Data on the web - an inconvenient truth
PPTX
Conventions of a MUSIC VIDEO!!
PPTX
Adding Rules on Existing Hypermedia APIs
PPTX
Goal based denial and wishful thinking
PPTX
Is interactive teaching content
PPTX
Ie business school question i. lc
Hydra: A Vocabulary for Hypermedia-Driven Web APIs
Kringla.nu: linking and presenting linked data
Data on the web - an inconvenient truth
Conventions of a MUSIC VIDEO!!
Adding Rules on Existing Hypermedia APIs
Goal based denial and wishful thinking
Is interactive teaching content
Ie business school question i. lc

Viewers also liked (14)

DOCX
Resumer sur les tris
PPTX
Conventions of pop music videos
PDF
Cirrascale forest container march 2011
PDF
Sujet bac info 2012 g1, g2 et g3 avec correction
PPTX
Meet JodyL my Avatar
DOC
ganesh[5+ years] exp _Resume
PPTX
APIs and Linked Data: A match made in Heaven
PDF
Sujet bac info 2013 g1, g2 et g3 avec correction
PPT
Developing students’ listening skills with technology and e resources
PPTX
TYPES OF STRATEGIC MANAGEMENT
PPTX
Presentation of industrial hazards
PDF
Exercices pascal tous les chapitres
PPTX
Meet jody l21
PPTX
Meet jody l
Resumer sur les tris
Conventions of pop music videos
Cirrascale forest container march 2011
Sujet bac info 2012 g1, g2 et g3 avec correction
Meet JodyL my Avatar
ganesh[5+ years] exp _Resume
APIs and Linked Data: A match made in Heaven
Sujet bac info 2013 g1, g2 et g3 avec correction
Developing students’ listening skills with technology and e resources
TYPES OF STRATEGIC MANAGEMENT
Presentation of industrial hazards
Exercices pascal tous les chapitres
Meet jody l21
Meet jody l
Ad

Similar to Consuming APIs with Python (20)

PDF
Semantic Web & TYPO3
PDF
Mitigate Maliciousness -- jQuery Europe 2013
PDF
Extensible RESTful Applications with Apache TinkerPop
PPTX
Automatic discovery of Web API Specifications: an example-driven approach
PPTX
Example-driven Web API Specification Discovery
PPTX
Building Next-Generation Web APIs with JSON-LD and Hydra
PDF
REST easy with API Platform
PPTX
JSON-LD, Schema.org, and Structured data
PDF
Winning with Structured Data and Schema.org - OMLIVE 2018
PDF
Elasticsearch for SQL Users
PDF
Pragmatic Hypermedia REST APIs
PDF
Deep Dive: Strategic Importance of BaaS
PDF
API REST et client Javascript - Nuxeo Tour 2014 - Workshop
PDF
Infrastructure as Code: Manage your Architecture with Git
PPTX
Creating 3rd Generation Web APIs with Hydra
PDF
Strigil - lightning talks
PDF
Guillotina: The Asyncio REST Resource API
PPTX
Experiments in Data Portability 2
PDF
Connecting to the Pulse of the Planet with the Twitter Platform
PDF
A model based approach for developing event-driven architectures with AsyncAPI
Semantic Web & TYPO3
Mitigate Maliciousness -- jQuery Europe 2013
Extensible RESTful Applications with Apache TinkerPop
Automatic discovery of Web API Specifications: an example-driven approach
Example-driven Web API Specification Discovery
Building Next-Generation Web APIs with JSON-LD and Hydra
REST easy with API Platform
JSON-LD, Schema.org, and Structured data
Winning with Structured Data and Schema.org - OMLIVE 2018
Elasticsearch for SQL Users
Pragmatic Hypermedia REST APIs
Deep Dive: Strategic Importance of BaaS
API REST et client Javascript - Nuxeo Tour 2014 - Workshop
Infrastructure as Code: Manage your Architecture with Git
Creating 3rd Generation Web APIs with Hydra
Strigil - lightning talks
Guillotina: The Asyncio REST Resource API
Experiments in Data Portability 2
Connecting to the Pulse of the Planet with the Twitter Platform
A model based approach for developing event-driven architectures with AsyncAPI
Ad

Recently uploaded (20)

PPTX
CHAPTER 2 - PM Management and IT Context
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
top salesforce developer skills in 2025.pdf
PPTX
L1 - Introduction to python Backend.pptx
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPT
Introduction Database Management System for Course Database
PPTX
history of c programming in notes for students .pptx
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Transform Your Business with a Software ERP System
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
assetexplorer- product-overview - presentation
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
Introduction to Artificial Intelligence
CHAPTER 2 - PM Management and IT Context
VVF-Customer-Presentation2025-Ver1.9.pptx
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
How to Choose the Right IT Partner for Your Business in Malaysia
top salesforce developer skills in 2025.pdf
L1 - Introduction to python Backend.pptx
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Design an Analysis of Algorithms II-SECS-1021-03
Softaken Excel to vCard Converter Software.pdf
Wondershare Filmora 15 Crack With Activation Key [2025
Introduction Database Management System for Course Database
history of c programming in notes for students .pptx
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Transform Your Business with a Software ERP System
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Reimagine Home Health with the Power of Agentic AI​
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
assetexplorer- product-overview - presentation
Design an Analysis of Algorithms I-SECS-1021-03
Introduction to Artificial Intelligence

Consuming APIs with Python