How to use Flickr API with Python (Example)

Welcome to this tutorial where we will learn how to use the Flickr API with Python.


What is the Flickr API

Flickr has an API (short for Application Programming Interface) that allows to access Flickr data in a structured way, without the need of interacting with the user interface.

Subscribe to my Newsletter

How to Get a Flickr API Key

In order to interact with the Flickr API, you will need to get the Flickr API Keys.
You can view the API keys as the username and password to the API.

To create your Flickr API keys, go to

  1. Create an Application
    You will first need to create an application. Click on “create your first”.

    create flickr api app

  2. Request an API Key

    Then, make a request for an API key by clicking on “Request an API Key”request a flickr api key

Then, click on “Request an API Key”.

Flickr will create two API keys:

  • key: A public key that can be viewed as the username of your application
  • secret: A private key that can be viewed as the password of your application

Keep both in a safe place and do not share it to anyone.

You can find your API keys by going to the App Garden and selecting “Apps by You” on the right-hand side.

Install The Flickr API Python Library

$ pip install flickrapi

Store API Keys in a Separate File

Full Python Code

from flickrapi import FlickrAPI

from api_keys import flickr_keys

key, secret = flickr_keys.values()

flickr = FlickrAPI(

# All the extra data that I want to have

photos =
    text='Quebec City', # Search term
    per_page=5, # Number of results per page
    license='4,5,6,7,8,9,10',  # Attribution Licenses
    privacy_filter=1, #public photos
    safe_search=1 # is safe


To know which licenses that you want, look here.

I created a dictionary that can be used for attribution mapping.
{'0': {'name': 'All Rights Reserved', 'url': ''},
 '1': {'name': 'Attribution-NonCommercial-ShareAlike License',
  'url': ''},
 '2': {'name': 'Attribution-NonCommercial License',
  'url': ''},
 '3': {'name': 'Attribution-NonCommercial-NoDerivs License',
  'url': ''},
 '4': {'name': 'Attribution License',
  'url': ''},
 '5': {'name': 'Attribution-ShareAlike License',
  'url': ''},
 '6': {'name': 'Attribution-NoDerivs License',
  'url': ''},
 '7': {'name': 'No known copyright restrictions',
  'url': ''},
 '8': {'name': 'United States Government Work',
  'url': ''},
 '9': {'name': 'Public Domain Dedication (CC0)',
  'url': ''},
 '10': {'name': 'Public Domain Mark',
  'url': ''}}

Photo Sizes

parameterimage size
url_oOriginal size of image
url_cMedium-size image 800×800
url_qSquare image 150×150
url_sSquare image 75,75
url_tThumbnail image 100px on largest width
url_nSmall image 320px on largest width
Enjoyed This Post?