Python-Powered Stock Quotes: Empowering Your Financial Journey.

Getting stock quotes for trading.

Using Python you can easily obtain stock market quotes for any given asset/company and automate this process without requirement to use a web browser, so you can use a solution below that will provide necessary information in dataframe or JSON format.

The Python script below will make a HTTP request to "Yahoo Finance" API - the gold standard for stock-data APIs available for both individual and enterprise-level users. The API use is free and reliable and wil provide you with stock quotes, up-to-date news, portfolio management resources, international market data, social interaction, mortgage and more...

Stock quotes.
Stock quotes meme.

Python Knowledge Base: Make coding great again.
- Updated: 2024-07-23 by Andrey BRATUS, Senior Data Analyst.

Obtained results in a form of dataframes or JSON files can be converted to any format suitable for further visualisation and financial data analysis to perform valuable business decisions. The script itself can be easily modified to obtain necessary historical data with any desired time aggregations.

Python code to obtain stock quotes:

#pip install yfinance

import yfinance as yf

company = "AAPL"
stock = yf.Ticker(company)

# get historical market data for maximum period

Stock quotes data output:

Stock quotes historical data.

Obtaining stock detailed INFO:

# get stock info

Stock INFO data output:

{'zip': '95014',
 'sector': 'Technology',
 'fullTimeEmployees': 154000,
 'longBusinessSummary': 'Apple Inc. designs, manufactures, and markets smartphones, personal computers, tablets, wearables, and accessories worldwide. It also sells various related services. In addition, the company offers iPhone, a line of smartphones; Mac, a line of personal computers; iPad, a line of multi-purpose tablets; AirPods Max, an over-ear wireless headphone; and wearables, home, and accessories comprising AirPods, Apple TV, Apple Watch, Beats products, HomePod, and iPod touch. Further, it provides AppleCare support services; cloud services store services; and operates various platforms, including the App Store that allow customers to discover and download applications and digital content, such as books, music, video, games, and podcasts. Additionally, the company offers various services, such as Apple Arcade, a game subscription service; Apple Music, which offers users a curated listening experience with on-demand radio stations; Apple News+, a subscription news and magazine service; Apple TV+, which offers exclusive original content; Apple Card, a co-branded credit card; and Apple Pay, a cashless payment service, as well as licenses its intellectual property. The company serves consumers, and small and mid-sized businesses; and the education, enterprise, and government markets. It distributes third-party applications for its products through the App Store. The company also sells its products through its retail and online stores, and direct sales force; and third-party cellular network carriers, wholesalers, retailers, and resellers. Apple Inc. was incorporated in 1977 and is headquartered in Cupertino, California.',
 'city': 'Cupertino',
 'phone': '408 996 1010',
 'state': 'CA',
 'country': 'United States',
 'companyOfficers': [],
 'website': '',
 'maxAge': 1,
 'address1': 'One Apple Park Way',
 'industry': 'Consumer Electronics',
 'ebitdaMargins': 0.3343,
 'profitMargins': 0.25709,
 'grossMargins': 0.43313998,
 'operatingCashflow': 118224003072,
 'revenueGrowth': 0.019,
 'operatingMargins': 0.30533,
 'ebitda': 129556996096,
 'targetLowPrice': 122,
 'recommendationKey': 'buy',
 'grossProfits': 152836000000,
 'freeCashflow': 83344621568,
 'targetMedianPrice': 185,
 'currentPrice': 150.7,
 'earningsGrowth': -0.077,
 'currentRatio': 0.865,
 'returnOnAssets': 0.22204,
 'numberOfAnalystOpinions': 42,
 'targetMeanPrice': 181.77,
 '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': 6.434,
 'beta3Year': None,
 'enterpriseToEbitda': 19.245,
 '52WeekChange': 0.054288507,
 'morningStarRiskRating': None,
 'forwardEps': 6.44,
 'revenueQuarterlyGrowth': None,
 'sharesOutstanding': 16070800384,
 'fundInceptionDate': None,
 'annualReportExpenseRatio': None,
 'totalAssets': None,
 'bookValue': 3.61,
 'sharesShort': 113066596,
 'sharesPercentSharesOut': 0.0069999998,
 'fundFamily': None,
 'lastFiscalYearEnd': 1632528000,
 'heldPercentInstitutions': 0.59741,
 'netIncomeToCommon': 99632996352,
 'trailingEps': 6.05,
 'lastDividendValue': 0.23,
 'SandP52WeekChange': -0.11115879,
 'priceToBook': 41.74515,
 'heldPercentInsiders': 0.0007,
 'nextFiscalYearEnd': 1695600000,
 'yield': None,
 'mostRecentQuarter': 1656115200,
 'shortRatio': 1.72,
 'sharesShortPreviousMonthDate': 1659052800,
 'floatShares': 16054199125,
 'beta': 1.234119,
 'enterpriseValue': 2493322362880,
 'priceHint': 2,
 'threeYearAverageReturn': None,
 'lastSplitDate': 1598832000,
 'lastSplitFactor': '4:1',
 'legalType': None,
 'lastDividendDate': 1659657600,
 'morningStarOverallRating': None,
 'earningsQuarterlyGrowth': -0.106,
 'priceToSalesTrailing12Months': 6.2493086,
 'dateShortInterest': 1661904000,
 'pegRatio': 2.69,
 'ytdReturn': None,
 'forwardPE': 23.40062,
 'lastCapGain': None,
 'shortPercentOfFloat': 0.0069999998,
 'sharesShortPriorMonth': 107535584,
 'impliedSharesOutstanding': 0,
 'category': None,
 'fiveYearAverageReturn': None,
 'previousClose': 152.37,
 'regularMarketOpen': 151.21,
 'twoHundredDayAverage': 160.8852,
 'trailingAnnualDividendYield': 0.0058410447,
 'payoutRatio': 0.1471,
 'volume24Hr': None,
 'regularMarketDayHigh': 151.35,
 'navPrice': None,
 'averageDailyVolume10Day': 95923830,
 'regularMarketPreviousClose': 152.37,
 'fiftyDayAverage': 159.475,
 'trailingAnnualDividendRate': 0.89,
 'open': 151.21,
 'toCurrency': None,
 'averageVolume10days': 95923830,
 'expireDate': None,
 'algorithm': None,
 'dividendRate': 0.92,
 'exDividendDate': 1659657600,
 'circulatingSupply': None,
 'startDate': None,
 'regularMarketDayLow': 148.37,
 'currency': 'USD',
 'trailingPE': 24.90909,
 'regularMarketVolume': 162278841,
 'lastMarket': None,
 'maxSupply': None,
 'openInterest': None,
 'marketCap': 2421869510656,
 'volumeAllCurrencies': None,
 'strikePrice': None,
 'averageVolume': 74343414,
 'dayLow': 148.37,
 'ask': 0,
 'askSize': 800,
 'volume': 162278841,
 'fiftyTwoWeekHigh': 182.94,
 'fromCurrency': None,
 'fiveYearAvgDividendYield': 1.03,
 'fiftyTwoWeekLow': 129.04,
 'bid': 0,
 'tradeable': False,
 'dividendYield': 0.0061000003,
 'bidSize': 1000,
 'dayHigh': 151.35,
 'coinMarketCapLink': None,
 'regularMarketPrice': 150.7,
 'preMarketPrice': 149.35,
 'logo_url': '',
 'trailingPegRatio': 2.7099}

See also related topics: