Examples of APIs

# Begin Rapid API Code
import requests

url = "https://coinranking1.p.rapidapi.com/coins"
querystring = {"referenceCurrencyUuid":"yhjMzLPhuIDl","timePeriod":"24h","tiers[0]":"1","orderBy":"marketCap","orderDirection":"desc","limit":"50","offset":"0"}
headers = {
	"X-RapidAPI-Key": "2348020badmshecfd384514830c4p1f8a42jsn72e4bf449cdf",  # place your key here
	"X-RapidAPI-Host": "coinranking1.p.rapidapi.com"
}

response = requests.request("GET", url, headers=headers, params=querystring)
#print(response.text),code that was here, and prints data but not organized
# End Rapid API Code
json = response.json()  # convert response to python json object

# Observe data from an API.  This is how data transports over the internet in a "JSON" text form
# - The JSON "text" is formed in dictionary {} and list [] divisions
# - To read the result, Data Scientist of  Developer converts JSON into human readable form
# - Review the first line, look for the keys --  "status" and "data"

for coin in json["data"]["coins"]:
	print(f'{coin["symbol"]} {coin["name"]} {coin["price"]}')
BTC Bitcoin 19319.010248550865
ETH Ethereum 1298.5373263339568
USDT Tether USD 1.0042914822031264
USDC USDC 1.0033426475380618
BNB Binance Coin 271.99903725788334
XRP XRP 0.4670249588334815
BUSD Binance USD 1.0046787901796796
ADA Cardano 0.36234791981912234
SOL Solana 30.079347713948852
DOGE Dogecoin 0.05954176340368893
MATIC Polygon 0.8418230219658197
DOT Polkadot 6.111645460783446
DAI Dai 1.0018636812091348
SHIB Shiba Inu 0.000010070780267767
TRX TRON 0.06210744215685524
WETH Wrapped Ether 1301.448403173206
UNI Uniswap 6.474269303096446
WBTC Wrapped BTC 19334.29792021206
AVAX Avalanche 15.834363139223417
CAKE PancakeSwap 4.4521595241644185
OKB OKB 16.65450028901999
ATOM Cosmos 12.266523398282382
LTC Litecoin 51.27956765904166
FTT FTX Token 23.50563446495291
ETC Ethereum Classic 23.49423351862973
XMR Monero 146.68419417150588
XLM Stellar 0.11137118902545307
ALGO Algorand 0.31825150928458706
BTCB Bitcoin BEP2 19419.051868679657
CRO Cronos 0.10764922282684228
BCH Bitcoin Cash 108.04270318039102
WEMIX WEMIX TOKEN 2.003006717281343
QNT Quant 195.71054623554437
ENS EnergySwap 18.950517432838012
NEAR NEAR Protocol 2.929763822112119
LUNC Terra Classic 0.000250507699702107
HT Huobi Token 7.792767485827178
FLOW Flow 1.5146727376138875
FIL Filecoin 5.108727276596857
VET VeChain 0.022727498272554873
HBAR Hedera 0.06164337265531565
MANA Decentraland 0.6261628362964291
FRAX Frax 1.0021877097270047
EGLD Elrond 56.7868482212396
ICP Internet Computer (DFINITY) 4.906419137898225
XTZ Tezos 1.3619123720360558
IMX Immutable X 0.6120427035515059
LDO Lido DAO Token 1.4594240484897618
SAND The Sandbox 0.7664611182124907
AAVE Aave 80.35405565927665
"""
Requests is a HTTP library for the Python programming language.
The goal of the project is to make HTTP requests simpler and more human-friendly.
"""
 
import requests
 
url = "https://corona-virus-world-and-india-data.p.rapidapi.com/api"
 
headers = {
   "X-RapidAPI-Key": "561be3d3dcmsh26da5c03e252f9fp1d2d4fjsn25f9e92f38d8",
   "X-RapidAPI-Host": "corona-virus-world-and-india-data.p.rapidapi.com"
}
 
response = requests.request("GET", url, headers=headers)
 
print(response.json)
 
# This code looks for "world data"
print("World Totals")
world = response.json().get('world_total')  # turn response to json() so we can extract "world_total"
for key, value in world.items():  # this finds key, value pairs in country
   print(key, value)
 
print()
 
# This code looks for USA in "countries_stats"
print("Country Totals")
countries = response.json().get('countries_stat')
for country in countries:  # countries is a list
   if country["country_name"] == "USA":  # this filters for USA
       for key, value in country.items():  # this finds key, value pairs in country
           print(key, value)
<bound method Response.json of <Response [200]>>
World Totals
total_cases 509,268,964
new_cases 204,268
total_deaths 6,242,509
new_deaths 630
total_recovered 461,827,849
active_cases 41,198,606
serious_critical 42,510
total_cases_per_1m_population 65,334
deaths_per_1m_population 800.9
statistic_taken_at 2022-04-24 11:18:01

Country Totals
country_name USA
cases 82,649,779
deaths 1,018,316
region 
total_recovered 80,434,925
new_deaths 0
new_cases 0
serious_critical 1,465
active_cases 1,196,538
total_cases_per_1m_population 247,080
deaths_per_1m_population 3,044
total_tests 1,000,275,726
tests_per_1m_population 2,990,303