thaifin: ข้อมูลพื้นฐานหุ้น ง่ายแค่สามบรรทัด
The same author as PythaiNAV
A Python library for access thai stock fundamental data up to 10+ years.
- faster and lesser load to server with cachetools
- more robust with auto retry with expo wait via tenacity
- better than nothing docs with pdoc
ไพทอนไลบารี่สำหรับเข้าถึงข้อมูลปัจจัยพื้นฐานของหุ้นในตลาดไทยมากถึง 10+ ปี
Get Started
# Pick one ✨
$ pip install thaifin
$ conda install thaifin
# Import both classes for different use cases
from thaifin import Stock, Stocks
# Collection operations with Stocks class
# Get all stock symbols
all_symbols = Stocks.list()
# ['T', 'A', 'U', 'J', 'W', 'B', 'D', 'S', 'M', 'K', 'EE', ...
# Smart search with auto language detection
top5match = Stocks.search('จัสมิน') # Thai search
# [<Stock JTS - updated just now>, <Stock JAS - updated just now>, <Stock JASIF - updated just now>, ...
cp_stocks = Stocks.search('cp') # English search
# [<Stock CPALL - updated just now>, <Stock CPANEL - updated just now>, <Stock CPAXT - updated just now>, ...
# Get detailed stock list with company info
stock_df = Stocks.list_with_names()
# symbol name industry sector market
# 0 24CS Twenty-Four Con & Supply Public Company Limited Property & Construction - mai
# 1 2S 2S METAL PUBLIC COMPANY LIMITED Industrials Steel and Metal Products SET
# Filter stocks by sector or market
banking_stocks = Stocks.filter_by_sector('Banking')
mai_stocks = Stocks.filter_by_market('mai')
# Individual stock operations with Stock class
stock = Stock('PTT')
# <Stock PTT - updated just now>
# Access company information
print(f"Company: {stock.company_name}")
print(f"Sector: {stock.sector}")
print(f"Industry: {stock.industry}")
# Get financial data as pandas DataFrames
stock.quarter_dataframe
# Cash DA ... FinancingActivities Asset
# Time ...
# 2009Q1 9.383006e+07 1.070218e+07 ... 3.101551e+07 9.453044e+08
# 2009Q2 9.643438e+07 8.893013e+06 ... 3.195314e+07 1.042480e+09
# 2009Q3 1.050549e+08 1.127702e+07 ... 1.100019e+07 1.099084e+09
# 2009Q4 1.040559e+08 1.227756e+07 ... -1.356621e+07 1.103590e+09
# ...
# 2019Q4 2.925425e+08 3.581462e+07 ... -2.179443e+07 2.484439e+09
# 2020Q1 2.543450e+08 3.586543e+07 ... -2.705637e+07 2.499666e+09
# 2020Q2 2.578579e+08 3.460213e+07 ... 2.117104e+07 2.449277e+09
# [46 rows x 35 columns]
stock.yearly_dataframe
# Cash DA ... FinancingActivities Asset
# Fiscal ...
# 2009 1.040559e+08 4.314976e+07 ... 6.040263e+07 1.103590e+09
# 2010 1.356320e+08 5.122258e+07 ... 3.761321e+06 1.249148e+09
# 2011 1.161321e+08 5.531816e+07 ... -4.542309e+07 1.402412e+09
# 2012 1.369176e+08 6.523743e+07 ... 2.771070e+07 1.631320e+09
# 2013 1.576835e+08 7.631456e+07 ... -5.579036e+07 1.801722e+09
# 2014 2.037854e+08 1.170070e+08 ... -4.731543e+07 1.779179e+09
# 2015 2.399779e+08 1.488855e+08 ... -1.638133e+08 2.173996e+09
# 2016 2.155664e+08 1.297570e+08 ... -1.162034e+08 2.232331e+09
# 2017 1.661890e+08 1.171472e+08 ... -1.624979e+08 2.232314e+09
# 2018 2.921843e+08 1.235563e+08 ... -1.114676e+08 2.355484e+09
# 2019 2.925425e+08 1.332042e+08 ... -7.022567e+07 2.484439e+09
# [11 rows x 35 columns]
Columns Data
class QuarterFinancialSheetDatum(BaseModel):
security_id: str
fiscal: int
quarter: int
cash: Optional[str]
da: Optional[str]
debt_to_equity: Optional[str]
equity: Optional[str]
earning_per_share: Optional[str]
earning_per_share_yoy: Optional[str]
earning_per_share_qoq: Optional[str]
gpm: Optional[str]
gross_profit: Optional[str]
net_profit: Optional[str]
net_profit_yoy: Optional[str]
net_profit_qoq: Optional[str]
npm: Optional[str]
revenue: Optional[str]
revenue_yoy: Optional[str]
revenue_qoq: Optional[str]
roa: Optional[str]
roe: Optional[str]
sga: Optional[str]
sga_per_revenue: Optional[str]
total_debt: Optional[str]
dividend_yield: Optional[str]
book_value_per_share: Optional[str]
close: Optional[str]
mkt_cap: Optional[str]
price_earning_ratio: Optional[str]
price_book_value: Optional[str]
ev_per_ebit_da: Optional[str]
ebit_dattm: Optional[str]
paid_up_capital: Optional[str]
cash_cycle: Optional[str]
operating_activities: Optional[str]
investing_activities: Optional[str]
financing_activities: Optional[str]
asset: Optional[str]
end_of_year_date: Optional[str]
Disclaimer
เราไม่รับประกันความเสียหายใดๆทั้งสิ้นที่เกิดจาก แหล่งข้อมูล, library, source code,sample code, documentation, library dependencies และอื่นๆ
FAQ
Q: อยากขอบคุณอ่ะ อยากตอบแทนอ่ะ 😋 ทำไงดี?
A: ถ้าเป็น developer สามารถช่วยส่ง PR หรือ pull request ได้ครับ ไม่ว่าจะเป็นงานเล็กน้อยเช่นแก้การพิมพ์ผิด หรือช่วยทำคู่มือ ยินดีมากๆครับ สามารถสนับสนุนผม
โดยการบริจาคครั้งเดียวผ่าน Ko-fi หรือ patreon ก็ได้เช่นกันครับ นอกจากนี้ยังสามารถเขียนให้กำลังใจผมได้ทาง
Q: แจ้งปัญหาไงอ่ะ ?
A: ถ้าเป็น error วิธีการใช้งานเขียน stackoverflow ได้ครับ ถ้าเป็น bug หรืออยากแนะนำขอ feature เขียน issue มาได้ครับ
Q: ข้อมูลมาจากไหน เชื่อถือได้แค่ไหน ?
A: ข้อมูลมาจากสาธารณะหลายแหล่งครับ ตอนที่เขียนมีเว็ป Finnomena, Set, Settrade เชื่อถือได้ไม่ได้คงต้องตัดสินเองนะครับ
Q: สร้างมาทำไม ?
A: สมัยเป็นนักศึกษา ผมก็อยากได้สิ่งนี้มาก่อนครับ เป็นเครื่องมือช่วยประกอบการลงทุน และใช้ความรู้ทาง data science กับข้อมูลได้ ตอนนั้นไม่มีใครทำครับ ข้อมูลผูกขาดเฉพาะกับบริษัทลงทุนเท่านั้น ตอนนี้ก็ยังเหมือนเดิม เพิ่มเติมคือผมมีความสามารถที่จะสร้างมัน ก็อยากให้คนรุ่นต่อไปได้มี library ดีๆ เป็นสมบัติ ของทุกคน(License ISC) ผมจึงใช้เวลาส่วนตัวมาพัฒนาครับ ทุกคนให้ความรักมันด้วยนะครับ code ก็ต้องการความรักนะ อิอิ
Metadata
Release files for thaifin 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| thaifin-1.1.0.tar.gz | 309.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| thaifin-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 330.4 kB
Release files / thaifin-1.1.0.tar.gz
| Download URL | thaifin-1.1.0.tar.gz |
|---|---|
| Size | 309.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
75a8ab2b22588065bf20808c3bb4a156654c7ad4c384e29acb13b42985e16448
|
|
BLAKE2b-256 checksum How to use checksums |
f0740c9a7d710d085728ac88a226279e64acc7636af8bc68d85b8b641b2f6f7a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.3
|
Release files / thaifin-1.1.0-py3-none-any.whl
| Download URL | thaifin-1.1.0-py3-none-any.whl |
|---|---|
| Size | 20.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c90739b01edb786d6c41cd625cf047ab632be577ae07b7ea1ed268b6ef32071b
|
|
BLAKE2b-256 checksum How to use checksums |
59fa9fff047a29b3a89cebebac7d4343e74b64da6a345d47c8190d0b1d20eaae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.3
|
Security for thaifin 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.