yfin-cli 0.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
src/__init__.py ADDED
@@ -0,0 +1 @@
1
+ # yfin CLI - A command-line wrapper for yfinance
src/cli.py ADDED
@@ -0,0 +1,133 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ yfin CLI - A command-line tool for Yahoo Finance data
4
+ """
5
+
6
+ import typer
7
+ from .typer import OutputType, default_output
8
+ from .commands.stock import (
9
+ history,
10
+ dividends,
11
+ fast_info,
12
+ news,
13
+ )
14
+ from .commands.market import market_status
15
+ from .commands.calendar import (
16
+ calendar_earnings,
17
+ calendar_economic_events,
18
+ calendar_ipo,
19
+ )
20
+ from .commands.financials import (
21
+ income_stmt,
22
+ balance_sheet,
23
+ cashflow,
24
+ earnings_dates,
25
+ sec_filings,
26
+ )
27
+ from .commands.analysis import (
28
+ recommendations,
29
+ upgrades_downgrades,
30
+ price_targets,
31
+ earnings_estimate,
32
+ revenue_estimate,
33
+ earnings_history,
34
+ eps_trend,
35
+ eps_revisions,
36
+ growth_estimates,
37
+ insider_purchases,
38
+ insider_transactions,
39
+ insider_roster_holders,
40
+ major_holders,
41
+ institutional_holders,
42
+ mutualfund_holders,
43
+ )
44
+ from .commands.sector import (
45
+ sector_keys,
46
+ sector_industries,
47
+ sector_overview,
48
+ sector_research_reports,
49
+ sector_top_companies,
50
+ sector_top_etfs,
51
+ sector_top_mutual_funds,
52
+ )
53
+ from .commands.industry import (
54
+ industry_overview,
55
+ industry_research_reports,
56
+ industry_top_companies,
57
+ industry_top_growth_companies,
58
+ industry_top_performing_companies,
59
+ )
60
+ from .commands.screen import (
61
+ screen,
62
+ screen_query_fields,
63
+ screen_query_values,
64
+ screen_predefined_queries,
65
+ )
66
+
67
+ app = typer.Typer(
68
+ name="yfin",
69
+ help="A command-line interface for Yahoo Finance data",
70
+ no_args_is_help=True,
71
+ )
72
+
73
+
74
+ @app.callback()
75
+ def main(ctx: typer.Context, output: OutputType = default_output):
76
+ ctx.ensure_object(dict)
77
+ ctx.obj["output"] = output
78
+
79
+
80
+ app.command(rich_help_panel="Stock")(history)
81
+ app.command(rich_help_panel="Stock")(dividends)
82
+ app.command(rich_help_panel="Stock")(fast_info)
83
+ app.command(rich_help_panel="Stock")(news)
84
+
85
+ app.command(rich_help_panel="Market")(market_status)
86
+
87
+ app.command(rich_help_panel="Calendar")(calendar_earnings)
88
+ app.command(rich_help_panel="Calendar")(calendar_economic_events)
89
+ app.command(rich_help_panel="Calendar")(calendar_ipo)
90
+
91
+ app.command(rich_help_panel="Financials")(income_stmt)
92
+ app.command(rich_help_panel="Financials")(balance_sheet)
93
+ app.command(rich_help_panel="Financials")(cashflow)
94
+ app.command(rich_help_panel="Financials")(earnings_dates)
95
+ app.command(rich_help_panel="Financials")(sec_filings)
96
+
97
+ app.command(rich_help_panel="Analysis")(recommendations)
98
+ app.command(rich_help_panel="Analysis")(upgrades_downgrades)
99
+ app.command(rich_help_panel="Analysis")(price_targets)
100
+ app.command(rich_help_panel="Analysis")(earnings_estimate)
101
+ app.command(rich_help_panel="Analysis")(revenue_estimate)
102
+ app.command(rich_help_panel="Analysis")(earnings_history)
103
+ app.command(rich_help_panel="Analysis")(eps_trend)
104
+ app.command(rich_help_panel="Analysis")(eps_revisions)
105
+ app.command(rich_help_panel="Analysis")(growth_estimates)
106
+ app.command(rich_help_panel="Analysis")(insider_purchases)
107
+ app.command(rich_help_panel="Analysis")(insider_transactions)
108
+ app.command(rich_help_panel="Analysis")(insider_roster_holders)
109
+ app.command(rich_help_panel="Analysis")(major_holders)
110
+ app.command(rich_help_panel="Analysis")(institutional_holders)
111
+ app.command(rich_help_panel="Analysis")(mutualfund_holders)
112
+
113
+ app.command(rich_help_panel="Sector")(sector_keys)
114
+ app.command(rich_help_panel="Sector")(sector_industries)
115
+ app.command(rich_help_panel="Sector")(sector_overview)
116
+ app.command(rich_help_panel="Sector")(sector_research_reports)
117
+ app.command(rich_help_panel="Sector")(sector_top_companies)
118
+ app.command(rich_help_panel="Sector")(sector_top_etfs)
119
+ app.command(rich_help_panel="Sector")(sector_top_mutual_funds)
120
+
121
+ app.command(rich_help_panel="Industry")(industry_overview)
122
+ app.command(rich_help_panel="Industry")(industry_research_reports)
123
+ app.command(rich_help_panel="Industry")(industry_top_companies)
124
+ app.command(rich_help_panel="Industry")(industry_top_growth_companies)
125
+ app.command(rich_help_panel="Industry")(industry_top_performing_companies)
126
+
127
+ app.command(rich_help_panel="Screen")(screen)
128
+ app.command(rich_help_panel="Screen")(screen_query_fields)
129
+ app.command(rich_help_panel="Screen")(screen_query_values)
130
+ app.command(rich_help_panel="Screen")(screen_predefined_queries)
131
+
132
+ if __name__ == "__main__":
133
+ app()
File without changes
@@ -0,0 +1,153 @@
1
+ import yfinance as yf
2
+ from ..typer import TickerType
3
+ from ..decorators import command
4
+ from ..utils import data_frame_to_list
5
+
6
+
7
+ @command
8
+ def recommendations(ticker: TickerType):
9
+ """
10
+ Get analyst recommendations for a stock ticker: number of buy, sell and hold in different time periods.
11
+ """
12
+ stock = yf.Ticker(ticker)
13
+ data_frame = stock.get_recommendations()
14
+ return data_frame_to_list(data_frame)
15
+
16
+
17
+ @command
18
+ def upgrades_downgrades(ticker: TickerType):
19
+ """
20
+ Get the analyst upgrades and downgrades history for a stock ticker.
21
+ """
22
+ stock = yf.Ticker(ticker)
23
+ data_frame = stock.get_upgrades_downgrades()
24
+ return data_frame_to_list(data_frame)
25
+
26
+
27
+ @command
28
+ def price_targets(ticker: TickerType):
29
+ """
30
+ Get the analyst price targets for a stock ticker.
31
+ """
32
+ stock = yf.Ticker(ticker)
33
+ return stock.get_analyst_price_targets()
34
+
35
+
36
+ @command
37
+ def earnings_estimate(ticker: TickerType):
38
+ """
39
+ Get analyst earnings estimate for a stock ticker.
40
+ """
41
+ stock = yf.Ticker(ticker)
42
+ data_frame = stock.get_earnings_estimate()
43
+ return data_frame_to_list(data_frame)
44
+
45
+
46
+ @command
47
+ def revenue_estimate(ticker: TickerType):
48
+ """
49
+ Get analyst revenue estimate for a stock ticker.
50
+ """
51
+ stock = yf.Ticker(ticker)
52
+ data_frame = stock.get_revenue_estimate()
53
+ return data_frame_to_list(data_frame)
54
+
55
+
56
+ @command
57
+ def earnings_history(ticker: TickerType):
58
+ """
59
+ Get analyst earnings history for a stock ticker.
60
+ """
61
+ stock = yf.Ticker(ticker)
62
+ data_frame = stock.get_earnings_history()
63
+ return data_frame_to_list(data_frame)
64
+
65
+
66
+ @command
67
+ def eps_trend(ticker: TickerType):
68
+ """
69
+ Get analyst eps trend for a stock ticker.
70
+ """
71
+ stock = yf.Ticker(ticker)
72
+ data_frame = stock.get_eps_trend()
73
+ return data_frame_to_list(data_frame)
74
+
75
+
76
+ @command
77
+ def eps_revisions(ticker: TickerType):
78
+ """
79
+ Get analyst eps revisions for a stock ticker.
80
+ """
81
+ stock = yf.Ticker(ticker)
82
+ data_frame = stock.get_eps_revisions()
83
+ return data_frame_to_list(data_frame)
84
+
85
+
86
+ @command
87
+ def growth_estimates(ticker: TickerType):
88
+ """
89
+ Get analyst growth estimates for a stock ticker.
90
+ """
91
+ stock = yf.Ticker(ticker)
92
+ data_frame = stock.get_growth_estimates()
93
+ return data_frame_to_list(data_frame)
94
+
95
+
96
+ @command
97
+ def insider_purchases(ticker: TickerType):
98
+ """
99
+ Get insider purchases for a stock ticker.
100
+ """
101
+ stock = yf.Ticker(ticker)
102
+ data_frame = stock.get_insider_purchases()
103
+ return data_frame_to_list(data_frame)
104
+
105
+
106
+ @command
107
+ def insider_transactions(ticker: TickerType):
108
+ """
109
+ Get insider transactions for a stock ticker.
110
+ """
111
+ stock = yf.Ticker(ticker)
112
+ data_frame = stock.get_insider_transactions()
113
+ return data_frame_to_list(data_frame)
114
+
115
+
116
+ @command
117
+ def insider_roster_holders(ticker: TickerType):
118
+ """
119
+ Get insider roster holders for a stock ticker.
120
+ """
121
+ stock = yf.Ticker(ticker)
122
+ data_frame = stock.get_insider_roster_holders()
123
+ return data_frame_to_list(data_frame)
124
+
125
+
126
+ @command
127
+ def major_holders(ticker: TickerType):
128
+ """
129
+ Get major holders for a stock ticker.
130
+ """
131
+ stock = yf.Ticker(ticker)
132
+ data_frame = stock.get_major_holders()
133
+ return data_frame_to_list(data_frame, index_name="Breakdown")
134
+
135
+
136
+ @command
137
+ def institutional_holders(ticker: TickerType):
138
+ """
139
+ Get institutional holders for a stock ticker.
140
+ """
141
+ stock = yf.Ticker(ticker)
142
+ data_frame = stock.get_institutional_holders()
143
+ return data_frame_to_list(data_frame)
144
+
145
+
146
+ @command
147
+ def mutualfund_holders(ticker: TickerType):
148
+ """
149
+ Get mutual fund holders for a stock ticker.
150
+ """
151
+ stock = yf.Ticker(ticker)
152
+ data_frame = stock.get_mutualfund_holders()
153
+ return data_frame_to_list(data_frame)
@@ -0,0 +1,84 @@
1
+ import yfinance as yf
2
+ from ..typer import (
3
+ StartDateType,
4
+ EndDateType,
5
+ LimitType,
6
+ default_limit,
7
+ OffsetType,
8
+ default_offset,
9
+ MarketCapType,
10
+ default_market_cap,
11
+ )
12
+ from ..decorators import command
13
+ from ..utils import compact, data_frame_to_list, default_end_from_start
14
+
15
+
16
+ @command
17
+ def calendar_earnings(
18
+ start: StartDateType,
19
+ end: EndDateType = None,
20
+ limit: LimitType = default_limit,
21
+ offset: OffsetType = default_offset,
22
+ market_cap: MarketCapType = default_market_cap,
23
+ ):
24
+ """
25
+ Get earnings calendar.
26
+ """
27
+ end = default_end_from_start(start, end)
28
+ kwargs = compact(
29
+ limit=limit,
30
+ offset=offset,
31
+ start=start,
32
+ end=end,
33
+ market_cap=market_cap,
34
+ )
35
+
36
+ calendars = yf.Calendars()
37
+ data_frame = calendars.get_earnings_calendar(**kwargs)
38
+ return data_frame_to_list(data_frame)
39
+
40
+
41
+ @command
42
+ def calendar_economic_events(
43
+ start: StartDateType,
44
+ end: EndDateType = None,
45
+ limit: LimitType = default_limit,
46
+ offset: OffsetType = default_offset,
47
+ ):
48
+ """
49
+ Get economic events calendar.
50
+ """
51
+ end = default_end_from_start(start, end)
52
+ kwargs = compact(
53
+ limit=limit,
54
+ offset=offset,
55
+ start=start,
56
+ end=end,
57
+ )
58
+
59
+ calendars = yf.Calendars()
60
+ data_frame = calendars.get_economic_events_calendar(**kwargs)
61
+ return data_frame_to_list(data_frame)
62
+
63
+
64
+ @command
65
+ def calendar_ipo(
66
+ start: StartDateType,
67
+ end: EndDateType = None,
68
+ limit: LimitType = default_limit,
69
+ offset: OffsetType = default_offset,
70
+ ):
71
+ """
72
+ Get IPO calendar.
73
+ """
74
+ end = default_end_from_start(start, end)
75
+ kwargs = compact(
76
+ limit=limit,
77
+ offset=offset,
78
+ start=start,
79
+ end=end,
80
+ )
81
+
82
+ calendars = yf.Calendars()
83
+ data_frame = calendars.get_ipo_info_calendar(**kwargs)
84
+ return data_frame_to_list(data_frame)
@@ -0,0 +1,83 @@
1
+ import yfinance as yf
2
+ from ..typer import (
3
+ TickerType,
4
+ FrequencyType,
5
+ ExtendedFrequencyType,
6
+ default_frequency,
7
+ OffsetType,
8
+ default_offset,
9
+ LimitType,
10
+ default_limit,
11
+ )
12
+ from ..utils import data_frame_to_list
13
+ from ..decorators import command
14
+
15
+
16
+ @command
17
+ def income_stmt(
18
+ ticker: TickerType,
19
+ frequency: ExtendedFrequencyType = default_frequency,
20
+ ):
21
+ """
22
+ Get income statement for a ticker.
23
+ """
24
+ stock = yf.Ticker(ticker)
25
+ data_frame = stock.get_income_stmt(pretty=True, freq=frequency)
26
+ if data_frame is None:
27
+ return None
28
+ return data_frame_to_list(data_frame.T, index_name="Date")
29
+
30
+
31
+ @command
32
+ def balance_sheet(
33
+ ticker: TickerType,
34
+ frequency: FrequencyType = default_frequency,
35
+ ):
36
+ """
37
+ Get balance sheet for a ticker.
38
+ """
39
+ stock = yf.Ticker(ticker)
40
+ data_frame = stock.get_balance_sheet(pretty=True, freq=frequency)
41
+ if data_frame is None:
42
+ return None
43
+ return data_frame_to_list(data_frame.T, index_name="Date")
44
+
45
+
46
+ @command
47
+ def cashflow(
48
+ ticker: TickerType,
49
+ frequency: ExtendedFrequencyType = default_frequency,
50
+ ):
51
+ """
52
+ Get cash flow statement for a ticker.
53
+ """
54
+ stock = yf.Ticker(ticker)
55
+ data_frame = stock.get_cashflow(pretty=True, freq=frequency)
56
+ if data_frame is None:
57
+ return None
58
+ return data_frame_to_list(data_frame.T, index_name="Date")
59
+
60
+
61
+ @command
62
+ def earnings_dates(
63
+ ticker: TickerType,
64
+ limit: LimitType = default_limit,
65
+ offset: OffsetType = default_offset,
66
+ ):
67
+ """
68
+ Get earnings dates, estimates, and reported EPS for a ticker.
69
+ """
70
+ stock = yf.Ticker(ticker)
71
+ data_frame = stock.get_earnings_dates(limit=limit, offset=offset)
72
+ return data_frame_to_list(data_frame)
73
+
74
+
75
+ @command
76
+ def sec_filings(
77
+ ticker: TickerType,
78
+ ):
79
+ """
80
+ Get SEC filings for a ticker.
81
+ """
82
+ stock = yf.Ticker(ticker)
83
+ return stock.get_sec_filings()
@@ -0,0 +1,44 @@
1
+ import yfinance as yf
2
+ from ..typer import IndustryKeyType
3
+ from ..decorators import command
4
+ from ..utils import data_frame_to_list
5
+
6
+
7
+ @command
8
+ def industry_overview(key: IndustryKeyType):
9
+ """
10
+ Get the overview information of the domain entity.
11
+ """
12
+ return yf.Industry(key).overview
13
+
14
+
15
+ @command
16
+ def industry_research_reports(key: IndustryKeyType):
17
+ """
18
+ Get research reports related to the domain entity.
19
+ """
20
+ return yf.Industry(key).research_reports
21
+
22
+
23
+ @command
24
+ def industry_top_companies(key: IndustryKeyType):
25
+ """
26
+ Get the top companies within the domain entity.
27
+ """
28
+ return data_frame_to_list(yf.Industry(key).top_companies)
29
+
30
+
31
+ @command
32
+ def industry_top_growth_companies(key: IndustryKeyType):
33
+ """
34
+ Get the top growth companies in the industry.
35
+ """
36
+ return data_frame_to_list(yf.Industry(key).top_growth_companies)
37
+
38
+
39
+ @command
40
+ def industry_top_performing_companies(key: IndustryKeyType):
41
+ """
42
+ Get the top performing companies in the industry.
43
+ """
44
+ return data_frame_to_list(yf.Industry(key).top_performing_companies)
src/commands/market.py ADDED
@@ -0,0 +1,11 @@
1
+ import yfinance as yf
2
+ from ..decorators import command
3
+
4
+
5
+ @command
6
+ def market_status():
7
+ """
8
+ Get the US market status.
9
+ """
10
+ market = yf.Market("US")
11
+ return market.status