The Problem
Clients need programmatic access to TradingView’s public screener data across stocks, crypto, forex, bonds, futures and coins. The native UI provides no API, and scraping the site manually is brittle and hard to maintain. A reusable Python wrapper that hides the HTTP details, validates field types and returns a tidy pandas.DataFrame removes the most common source of friction for quantitative teams.
What This Does
tvscreener implements a thin, type‑safe client library. Core screener classes live under tvscreener/core/ (e.g. stock.py, crypto.py) and inherit common logic from tvscreener/core/base.py. Field definitions are collected in tvscreener/field/ – the package’s hub (tvscreener/field/__init__.py) re‑exports 16 field classes and utilities such as add_rec and add_historical.
The optional MCP server (tvscreener/mcp/server.py) exposes a small HTTP/JSON endpoint that AI assistants (Claude, etc.) can call. It offers high‑level helpers like discover_fields, custom_query, search_stocks, and get_top_movers. The web UI in app/ (HTML + JS) drives the visual code generator that produces ready‑to‑run Python snippets.
How It Is Wired
Execution starts at the MCP entry points in tvscreener/mcp/server.py. For example, custom_query (line 103) invokes a chain of 12 internal functions, ultimately calling StockScreener._get_filter (used in 21 places) and get_url (network request) defined in tvscreener/util.py. The most‑used class is StockScreener – its methods appear in 46 distinct call sites.
core/base.py creates the HTTP payload, validates filters via tvscreener/filter.py, and forwards the request to TradingView. The response is parsed into a pandas.DataFrame by beauty.py.
The hub module tvscreener/field/__init__.py is referenced by 11 other modules and defines 65 functions and 16 classes; any change here has a large blast radius. Two import cycles exist (field/__init__.py ↔ filter.py), which increase cognitive load and risk of runtime errors. Deep nesting (max depth 6) appears in util.py, filter.py and the code‑gen script .dev/codegen/generate.py, making the control flow harder to follow.
Only two external effects are observed: a single file‑write in app/scripts/export_fields.py and a single outbound HTTP call in core/base.py. All other logic stays inside the repository.
How To Use It
# Install the library with optional MCP support
pip install "tvscreener[mcp]"
# Run the MCP server (entry point installed by the package)
tvscreener-mcp
The server listens on localhost:8000 (default). To screen stocks from Python:
from tvscreener import StockScreener, StockField
ss = StockScreener()
ss.where(StockField.PRICE > 50, StockField.VOLUME >= 1_000_000)
df = ss.get() # returns pandas.DataFrame
print(df.head())
The web UI is served from app/index.html; the bundled app/js/code-generator.js calls the MCP endpoints to generate the same Python code shown above.
Real‑World Use
A quant team can embed the library in nightly pipelines:
from tvscreener import StockScreener, STOCK_VALUATION_FIELDS
screener = StockScreener()
screener.select(*STOCK_VALUATION_FIELDS)
screener.where(StockField.MARKET_CAPITALIZATION.between(1e9, 5e10))
df = screener.get()
df.to_parquet("data/stock_valuation.parquet")
The resulting parquet file feeds downstream risk models without any custom scraping logic.
Code Health & Issues
- HIGH – Pin third‑party GitHub Actions to a commit SHA (
.github/workflows/*). - HIGH – No lockfile alongside
pyproject.toml; reproducing the exact dependency set is impossible. - MEDIUM – Dependabot/Renovate not configured; vulnerable transitive packages could linger.
- MEDIUM – No dependency‑vulnerability scan in CI; known CVEs would not be caught automatically.
- MEDIUM – Checkout step keeps the token; set
persist-credentials: falseincodecov.yml. - LOW – CI jobs lack
timeout-minutes; long‑running steps could block the schedule.
Additional static findings: two import cycles (field/__init__.py, filter.py), several oversized files (>800 LOC) and deep nesting (indentation depth 6) increase maintenance risk.
The Bottom Line
tvscreener delivers a functional, well‑documented Python wrapper for TradingView screener data and a convenient MCP server for AI‑driven queries. The core API is usable out‑of‑the‑box, but the codebase shows classic technical‑debt signals—import cycles, large modules and missing lockfiles—that should be addressed before relying on it for production‑critical pipelines. Engineers comfortable with Python and pandas will find it a practical shortcut, provided they budget time for the identified refactoring and security hardening.