There are 2 main ways:
Using
.content(simplest/official) (see Zhenyi Zhang's answerZhenyi Zhang's answer):import io # Note: io.BytesIO is StringIO.StringIO on Python2. import requests r = requests.get('http://lorempixel.com/400/200') r.raise_for_status() with io.BytesIO(r.content) as f: with Image.open(f) as img: img.show()Using
.raw(see Martijn Pieters's answerMartijn Pieters's answer):import requests r = requests.get('http://lorempixel.com/400/200', stream=True) r.raise_for_status() r.raw.decode_content = True # Required to decompress gzip/deflate compressed responses. with PIL.Image.open(r.raw) as img: img.show() r.close() # Safety when stream=True ensure the connection is released.
Timing both shows no noticeable difference.