Skip to main content

financialdatapy

financialdatapy is a package for getting a fundamental financial data of a company. Currently it supports financial data of companies listed in United States (NASDAQ, NYSE) and South Korea (KOSPI, KOSDAQ).

User can see the company's latest financial statement reported, standard financials, and historical stock price. financialdatapy will be a good choice for research purposes, and managing an investment portfolio.

Installation

To use financialdatapy, first install it using pip:

❗Python version above 3.10 is required to use financialdatapy .

pip install financialdatapy

Quick Start

financialdatapy supports three major financial statements of a company. Income statement, balance sheet, and cash flow. Also the user can select between annual and quarter financial statements.

API Key

❗When getting financial statements of a company listed in Korea stock exchange, API Key from DART should be provided in the system to successfully retrieve its data.

After receiving API key, store it on a .env file in the root directory of your project.

Inside .env file.

DART_API_KEY=xxxxxxxxxxxxxxxx

SEC User-Agent

❗When getting data of a company listed in US stock exchange, SEC requires every request to declare who is sending it. Requests without it are rejected with 403 Forbidden.

Store your own name and email on the same .env file, in the format SEC asks for.

Inside .env file.

SEC_USER_AGENT=App Name your@email.com

Browser User-Agent

investing.com, the data source for KOR stock price, rejects requests that do not come from a current browser. Declare your own browser's User-Agent to retrieve its data. If it is not set, a randomized User-Agent is sent instead, which investing.com refuses with 403 Forbidden.

You can find your browser's User-Agent by opening whatismybrowser.com , or by running navigator.userAgent in your browser's developer console.

Inside .env file.

USER_AGENT=xxxxxxxxxxxxxxxx

Initialization

from financialdatapy.stock import Stock

# Apple
us_comp = Stock('aapl')
# Samsung Electronics
kor_comp = Stock('005930', country_code='kor')  # should specify 'country_code' for stock exchange other than US

Values passed for financial statements and periods should follow the format below. If no argument is passed, it automatically retrieves income statement from annual report.

income_statement = us_comp.financials('income_statement')
balance_sheet = us_comp.financials('balance_sheet')
cash_flow = us_comp.financials('cash_flow')

# Annual Report
income_statement = kor_comp.financials('income_statement', 'annual')
# Quarterly Report
income_statement = kor_comp.financials('income_statement', 'quarter')

Financial Statement as reported

Financial statements reported by the company to a financial regulator. The elements in the financial statements are different from others, depending on the comapany and stock exchange.

United States Stock Exchange

us_comp = Stock('aapl')
ic_as_reported = us_comp.financials('income_statement', 'annual')

Korea Stock Exchange

kor_comp = Stock('005930', country_code='kor')
ic_as_reported = kor_comp.financials('income_statement', 'annual')

To see the full financial report from a browser, pass True in web. Supports both US exchange and KOR exchange.

us_comp.financials(web=True)
kor_comp.financials(web=True)

Standard Financial Statement

[!WARNING] Currently getting standard financial statements is not available. The investing.com endpoint it depends on responds with 403 Forbidden even to a current browser User-Agent, so setting USER_AGENT does not restore it.

Summarized financial statements of a company.

us_comp = Stock('msft')
std_ic = us_comp.financials('income_statement', 'annual', is_standard=True)

Historical Stock Data

[!IMPORTANT] Getting historical data of stocks listed in KOR exchange requires USER_AGENT to be set. See the Browser User-Agent section above. Without it the request is rejected with 403 Forbidden and price() raises requests.exceptions.HTTPError. US exchange is unaffected.

Historical stock price of the company.

us_comp = Stock('aapl')
price = us_comp.price('2021-1-1', '2021-1-5')

All of the above will return in pandas.DataFrame.

❗️Note

Data source of stock price data differ from US stock exchange to KOR stock exchange.

Exchange Source
USA finance.yahoo.com
KOR investing.com

List of Companies in Stock Exchange

United States Stock Exchange

from financialdatapy.stocklist import UsStockList

us_stock_list = UsStockList()
us_stock_list = us_stock_list.stock_list

Korea Stock Exchange

Api key is required to get the stock list of companies in Korea stock exchange. See more about the api key in the API Key section above.

from financialdatapy.stocklist import KorStockList

kor_stock_list = KorStockList()
kor_stock_list = kor_stock_list.stock_list

Contribute

It will be a great help if you contribute to the package. You can open issues here

Code style

The project basically follows PEP-8 , Google Python Style Guide.

Git commit messages

Conventional Commits

The project basically follows Conventional Commits. Click on the badge to see the details.

<type>[optional scope]: <description>

[optional body]

[optional footer(s)]

Documentation

See the full documentation here.

The documentation is built with Sphinx and deployed with Read the Docs.

License

Licensed under the MIT License

Credits

Data used in the package are from SEC EDGAR , finance.yahoo.com, investing.com.

Disclaimer

financialdatapy is not meant to be used in any kind of trading. The data might not be accurate, and timely. financialdatapy is aimed for people who use stock data in their portfolio management and researchers who need stock market data in their research. So if you are willing to use data for trading, there are lot more better options.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

financialdatapy-1.2.4.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

financialdatapy-1.2.4-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file financialdatapy-1.2.4.tar.gz.

File metadata

  • Download URL: financialdatapy-1.2.4.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for financialdatapy-1.2.4.tar.gz
Algorithm Hash digest
SHA256 9cac4f1b97f48c9a20066238ab80180c95864393d8af3790e75654d1306a8471
MD5 978645dc5be23937195bf1b9cfc5808a
BLAKE2b-256 f9af74adbae38358e2f2829f54d9167e875d0a35acfa4265406e084656da02c5

See more details on using hashes here.

File details

Details for the file financialdatapy-1.2.4-py3-none-any.whl.

File metadata

  • Download URL: financialdatapy-1.2.4-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for financialdatapy-1.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2957614b93d63c7748788a87928ae9cb98850815d8c0fdadfb78d270f945c49d
MD5 4165cff32396d5fd1dfadd4e46cb0dc9
BLAKE2b-256 6b6725cd851960ea30ecee845ab8a7963ee708c73ef95b0ada63d76ed4f8e12b

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.2.4 This release

2 files

1.2.3

2 files

1.2.2

2 files

1.2.1

2 files

1.2.0

2 files

1.1.0

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page