Making a simple request to APIs in python

Today, I would like to share about making a API request using ‘requests’ library in Python. Let’s take a look.

First of all, install the ‘requests’ library by the following command.

pip install requests

or

pip3 install requests

Here is the code to make a GET request to a public API.

import requests

api = 'https://catfact.ninja/fact'

response_data = requests.get(api)

response_data_json = response_data.json()

print(response_data_json)

The result is as follows.

{'fact': 'Lions are the only cats that live in groups, called prides. Every female within the pride is usually related.', 'length': 109}

This is the example request to a public API. You can learn more HERE for advanced usage.

Hope you enjoy that.

By Asahi



アプリ関連ニュース

お問い合わせはこちら

お問い合わせ・ご相談はお電話、またはお問い合わせフォームよりお受け付けいたしております。

tel. 06-6454-8833(平日 10:00~17:00)

お問い合わせフォーム