Example nbrequests

Pretty printing requests/responses from the python requests library in Jupyter notebook.


In [1]:
# autoreload for development
%load_ext autoreload
%autoreload 1
%aimport nbrequests

import requests
from nbrequests import display_request

GET request

Execute requests.get('...') and format the result in the notebook output using display_request(r).


In [2]:
r = requests.get('http://httpbin.org/get')
display_request(r)


GET
http://httpbin.org/get
200

Response

took 1.042982 seconds

POST request


In [3]:
r = requests.post('http://httpbin.org/post', data='text data')
display_request(r)
r = requests.post('http://httpbin.org/post', data=b'binary data')
display_request(r)


POST
http://httpbin.org/post
200

Request

text data

Response

took 0.507732 seconds
POST
http://httpbin.org/post
200

Request

b'binary data'

Response

took 0.510205 seconds

JSON POST request

JSON is currently renderer using Renderjson.


In [4]:
import json
r = requests.post('http://httpbin.org/post', json={"a": "b"})
display_request(r)


POST
http://httpbin.org/post
200

Request

Response

took 0.511623 seconds

500 error response


In [5]:
r = requests.get('http://httpbin.org/status/500')
display_request(r)


GET
http://httpbin.org/status/500
500

Response

Empty Response
took 0.509652 seconds