Files
yfinance-fork/cli/yfin/commands/auth.py
T
goldyard 057bc4493e Add yfin CLI + tool catalog + CLAUDE.md
Wraps the entire yfinance public API behind a single binary `yfin` with
51 subcommands across 13 namespaces (ticker, download, tickers, search,
lookup, market, sector, industry, calendars, screen, live, auth, config).
Output renders as Rich tables on TTY, JSON when piped; --format / --out
support table | json | ndjson | csv | tsv | parquet | yaml.

Highlights:
- 1857 LOC across 18 Python files under cli/yfin/
- Typer + Rich, packaged via hatchling + uv
- Install globally: `cd cli && uv tool install -e .`
- ~/.yfin/config.toml for persistent proxy/cookies/locale defaults
- Friendly YFRateLimitError handler (exit 2, no Rich traceback)
- Validated end-to-end with 33 live tests against Yahoo from a
  residential exit (AAPL, MSFT, NVDA, options, screens, calendars,
  financials, news, holders, parquet round-trip)

yfinance-tools.yaml is the single source of truth:
- tools (49)       — every public yfinance entry point with parameters
- cli (13 groups)  — exact CLI invocations, mapped back to tool names
- outputSchemas (27) — actual return shapes captured from live calls
- learnings (19)   — IP rate-limit, crumb handshake, Typer gotchas,
                     screen-build wrapping rules, upstream stubs, etc.

CLAUDE.md documents the upstream codebase layout for future agents.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-08 23:36:56 +08:00

49 lines
1.3 KiB
Python

"""`yfin auth ...` — Yahoo cookie / strategy management."""
from __future__ import annotations
from enum import Enum
import typer
import yfinance as yf
from .._shared import get_state
from .. import config as cfg_mod
class Strategy(str, Enum):
basic = "basic"
csrf = "csrf"
app = typer.Typer(no_args_is_help=True, help="Yahoo cookie / strategy management.")
@app.command("cookies")
def cookies(
ctx: typer.Context,
t: str = typer.Option(..., "--t", help='Yahoo "T" cookie value.'),
y: str = typer.Option(..., "--y", help='Yahoo "Y" cookie value.'),
save: bool = typer.Option(False, "--save/--no-save", help="Persist to ~/.yfin/config.toml."),
):
"""Inject Yahoo login cookies into the shared session."""
yf.Auth.set_login_cookies(t, y)
typer.echo("Cookies set on current session.")
if save:
st = get_state(ctx)
cfg = cfg_mod.load(st.config_path)
cfg.cookies_t = t
cfg.cookies_y = y
p = cfg_mod.save(cfg, st.config_path)
typer.echo(f"Saved to {p}.")
@app.command("strategy")
def strategy(
ctx: typer.Context,
strategy: Strategy = typer.Argument(...),
):
"""Force the cookie-acquisition strategy used by YfData (basic|csrf)."""
from yfinance.data import YfData
YfData()._cookie_strategy = strategy.value
typer.echo(f"Auth strategy set to {strategy.value}.")