dev-resources.site
for different kinds of informations.
Make API Call in Python
Published at
10/10/2022
Categories
python
Author
Code Something
Categories
1 categories in total
python
open
I wrote this quick tutorial to learn how to make API calls in Python after transitioning to it from JavaScript.
I thought making API calls in Python would be difficult. But I was wrong. It's actually straightforward (like many things in Python.)
To make an API call in Python follow these steps:
- Import
requests
package - Use
requests.get(URL)
method with the API url - Convert result to JSON object with
.json()
method on returned object. - Access JSON properties as Python dictionary (Using [""] brackets)
Here is a code example:
import requests
url = "http://api.weatherapi.com/v1/current.json?key=47a53ef1aeff4b29ba811204220210&q=London&aqi=no"
# Make API Call
response = requests.get(url)
# Convert result object to JSON dictionary
json = response.json()
# Get json.current.temp_f property from the JSON response
temperature = json["current"]["temp_f"]
# Print temperature from returned JSON object
print(temperature)
This tutorial is also available on YouTube:
Articles
12 articles in total
Free GPT For Lawyers
read article
Is There A Free or Discount Platform For Using GPT4 For Data Analysis?
read article
How to use ChatGPT4 for web development
read article
Can Chat GPT4 Be Used For Academic Writing?
read article
Make API Call in Python
currently reading
How To Fade In And Out In Premiere Pro
read article
ReMaking Twitter - Part 1
read article
Run JavaScript In VSCode
read article
Let's Run PHP On Localhost with XAMPP Server
read article
VSCode: Changing Font Size
read article
Git in VSCode
read article
Installing MinGW W64 with FFMPEG on Windows and fixing the weird "file downloaded incorrectly" error.
read article
Featured ones: