What is an API?

An API (Application Programming Interface) is used as a intermediary bridge between two software applications that stardizes protocol and conventions. In simple words an API could help us to send and receive data.

import requests

# Set number of rows to 10
r=10
# Set number of columns to 10
c=10
# Set number of mines to r*c/4
b = (r*c)//4
url = "https://minesweeper1.p.rapidapi.com/boards/new"

querystring = {"r":r,"c":c,"bombs":b}

headers = {
	"X-RapidAPI-Key": "9443d1725fmsha0cfacd48534f3cp1802cfjsn326b60d92795",
	"X-RapidAPI-Host": "minesweeper1.p.rapidapi.com"
}

response = requests.request("GET", url, headers=headers, params=querystring)
board = response.json().get("board")
for row in board:
	temp = ["M" if k == "-1" else k for k in [str(i) for i in row]]
	print(" ".join(temp))
#print(board)
1 1 2 M M 1 1 M M 2
3 M 3 2 2 1 1 3 M 2
M M 3 0 0 1 1 3 2 2
M M 2 0 0 1 M 3 M 3
3 4 3 1 0 1 2 5 M M
2 M M 3 1 0 1 M M 3
2 M M M 1 0 1 2 2 1
1 2 3 3 2 1 0 0 1 1
0 0 0 2 M 2 1 1 2 M
0 0 0 2 M 2 1 M 2 1
import requests

url = "https://stock-and-options-trading-data-provider.p.rapidapi.com/options/aapl"

headers = {
	"X-RapidAPI-Proxy-Secret": "a755b180-f5a9-11e9-9f69-7bf51e845926",
	"X-RapidAPI-Key": "9443d1725fmsha0cfacd48534f3cp1802cfjsn326b60d92795",
	"X-RapidAPI-Host": "stock-and-options-trading-data-provider.p.rapidapi.com"
}

response = requests.request("GET", url, headers=headers)
json = response.json()
print(response.text)
print(json["stock"])
def print_stock(json):
    stock_info = json["stock"]
    blacklist = ["longBusinessSummary", "coinMarketCapLink", "ebitda", "maxAge", "ebitdaMargins", "logo_url", "strikePrice", "volumeAllCurrencies", "startDate", "circulatingSupply", "navPrice"]
    print("Current Stock Information for Ticker: ", stock_info["symbol"])
    for key, value in stock_info.items():
        if key not in blacklist:
            print(key + ": " + str(value))
                
        
    
print_stock(json)
Current Stock Information for Ticker:  AAPL
zip: 95014
sector: Technology
fullTimeEmployees: 154000
city: Cupertino
phone: 408 996 1010
state: CA
country: United States
companyOfficers: []
website: https://www.apple.com
address1: One Apple Park Way
industry: Consumer Electronics
profitMargins: 0.25709
grossMargins: 0.43313998
operatingCashflow: 118224003072
revenueGrowth: 0.019
operatingMargins: 0.30533
targetLowPrice: 130
recommendationKey: buy
grossProfits: 152836000000
freeCashflow: 83344621568
targetMedianPrice: 185
currentPrice: 140.42
earningsGrowth: -0.077
currentRatio: 0.865
returnOnAssets: 0.22204
numberOfAnalystOpinions: 41
targetMeanPrice: 183.5
debtToEquity: 205.984
returnOnEquity: 1.62816
targetHighPrice: 220
totalCash: 48230998016
totalDebt: 119691001856
totalRevenue: 387541991424
totalCashPerShare: 3.001
financialCurrency: USD
revenuePerShare: 23.732
quickRatio: 0.697
recommendationMean: 1.9
exchange: NMS
shortName: Apple Inc.
longName: Apple Inc.
exchangeTimezoneName: America/New_York
exchangeTimezoneShortName: EDT
isEsgPopulated: False
gmtOffSetMilliseconds: -14400000
quoteType: EQUITY
symbol: AAPL
messageBoardId: finmb_24937
market: us_market
annualHoldingsTurnover: None
enterpriseToRevenue: 5.994
beta3Year: None
enterpriseToEbitda: 17.929
52WeekChange: -0.019046307
morningStarRiskRating: None
forwardEps: 6.46
revenueQuarterlyGrowth: None
sharesOutstanding: 16070800384
fundInceptionDate: None
annualReportExpenseRatio: None
totalAssets: None
bookValue: 3.61
sharesShort: 116076947
sharesPercentSharesOut: 0.0072000003
fundFamily: None
lastFiscalYearEnd: 1632528000
heldPercentInstitutions: 0.59582
netIncomeToCommon: 99632996352
trailingEps: 6.05
lastDividendValue: 0.23
SandP52WeekChange: -0.16544336
priceToBook: 38.897507
heldPercentInsiders: 0.00071000005
nextFiscalYearEnd: 1695600000
yield: None
mostRecentQuarter: 1656115200
shortRatio: 1.53
sharesShortPreviousMonthDate: 1660521600
floatShares: 16053877710
beta: 1.249815
enterpriseValue: 2322811584512
priceHint: 2
threeYearAverageReturn: None
lastSplitDate: 1598832000
lastSplitFactor: 4:1
legalType: None
lastDividendDate: 1659657600
morningStarOverallRating: None
earningsQuarterlyGrowth: -0.106
priceToSalesTrailing12Months: 5.823012
dateShortInterest: 1663200000
pegRatio: 2.42
ytdReturn: None
forwardPE: 21.736841
lastCapGain: None
shortPercentOfFloat: 0.0072000003
sharesShortPriorMonth: 115400891
impliedSharesOutstanding: 0
category: None
fiveYearAverageReturn: None
previousClose: 140.09
regularMarketOpen: 140.42
twoHundredDayAverage: 159.1368
trailingAnnualDividendYield: 0.006353059
payoutRatio: 0.1471
volume24Hr: None
regularMarketDayHigh: 141.89
averageDailyVolume10Day: 101319120
regularMarketPreviousClose: 140.09
fiftyDayAverage: 158.688
trailingAnnualDividendRate: 0.89
open: 140.42
toCurrency: None
averageVolume10days: 101319120
expireDate: None
algorithm: None
dividendRate: 0.92
exDividendDate: 1659657600
regularMarketDayLow: 138.5729
currency: USD
trailingPE: 23.209917
regularMarketVolume: 73717951
lastMarket: None
maxSupply: None
openInterest: None
marketCap: 2256661643264
averageVolume: 80128214
dayLow: 138.5729
ask: 141.03
askSize: 1000
volume: 73717951
fiftyTwoWeekHigh: 182.94
fromCurrency: None
fiveYearAvgDividendYield: 1.02
fiftyTwoWeekLow: 129.04
bid: 141.03
tradeable: False
dividendYield: 0.0066000004
bidSize: 1800
dayHigh: 141.89
regularMarketPrice: 140.42
lastUpdated: 10/10/2022