Skip to main content

tvkit

CI PyPI PyPI Downloads Python 3.11+ License: MIT Async/Await Type Safety

tvkit — Async Python client for TradingView market data.

Access real-time and historical TradingView data with a modern async Python API. Designed for quantitative research, trading tools, and data pipelines.

Features

  • Real-time OHLCV streaming via WebSocket with async generators
  • Automatic reconnection with exponential backoff — transient disconnects recovered transparently
  • Historical data retrieval by bar count or explicit date range
  • Automatic segmented fetching for large historical OHLCV date ranges (TradingView historical depth limits still apply)
  • Multi-market scanner: 69 global markets, 101+ financial metrics
  • Multi-format data export: Polars DataFrames, JSON, CSV
  • Symbol format auto-conversion: EXCHANGE-SYMBOL and EXCHANGE:SYMBOL both accepted
  • Async symbol validation with retry and flexible format support
  • Full type safety with Pydantic models throughout
  • Python 3.11+ with async/await and context manager patterns

Installation

Available on PyPI: https://pypi.org/project/tvkit/

uv add tvkit        # recommended
pip install tvkit

Quick Example

import asyncio
from tvkit.api.chart.ohlcv import OHLCV

async def main() -> None:
    async with OHLCV() as client:
        # Fetch last 10 daily bars for Apple
        bars = await client.get_historical_ohlcv(
            exchange_symbol="NASDAQ:AAPL",
            interval="1D",
            bars_count=10,
        )
    for bar in bars:
        print(bar.timestamp, bar.close)
        # 1785850200.0 309.38

asyncio.run(main())

Output:

timestamp date open high low close volume
1785850200.0 2026-08-04 302.725 310.42 301.32 309.38 68,000,969
1785936600.0 2026-08-05 309.36 311.71 305.67 311.0 49,438,763
1786023000.0 2026-08-06 314.34 316.2894 309.23 312.41 46,139,901
1786109400.0 2026-08-07 311.45 314.81 310.74 313.33 34,437,191
1786368600.0 2026-08-10 306.83 308.26 304.61 308.26 44,812,503

10 rows total, showing 5

date is derived — OHLCVBar has 6 fields: timestamp, open, high, low, close, volume

The print() above emits the first and sixth columns only: 1785850200.0 309.38.

Example output — live market values will differ.

See more working examples in examples/.

Authenticated Sessions

Authenticate with your TradingView account to unlock larger historical data windows beyond the anonymous 5,000-bar limit. See TradingView Pricing for the full plan comparison.

Plan Max bars per fetch
Basic (free) 5,000
Essential / Plus 10,000
Premium 20,000
Ultimate 40,000
# Browser cookie extraction — Chrome or Firefox (must be logged in to TradingView)
async with OHLCV(browser="chrome") as client:
    await client.wait_until_ready()           # optional: wait for probe-confirmed max_bars
    account = client.account
    if account:
        print(f"Tier: {account.tier}, max_bars: {account.max_bars}")
    bars = await client.get_historical_ohlcv(
        exchange_symbol="NASDAQ:AAPL",
        interval="1D",
        bars_count=10_000,
    )

# Firefox
async with OHLCV(browser="firefox") as client: ...

# Direct token injection (CI/CD — no browser required)
async with OHLCV(auth_token=os.environ["TVKIT_AUTH_TOKEN"]) as client: ...

# Anonymous (default — no changes required)
async with OHLCV() as client: ...

Environment variables (alternative to kwargs):

export TVKIT_BROWSER=chrome        # equivalent to OHLCV(browser="chrome")
export TVKIT_AUTH_TOKEN=<token>    # equivalent to OHLCV(auth_token=...)

Troubleshooting:

  • BrowserCookieError — not logged in to TradingView in the browser; log in and retry
  • ProfileFetchError — session expired; log out and back in to TradingView

More details: Authenticated Sessions Guide · Account Capabilities · Auth Reference


Automatic Reconnection

Reconnection is on by default — no changes needed to existing call sites:

async with OHLCV() as client:
    # Transient disconnects are recovered automatically (5 attempts, 1s–30s backoff).
    async for bar in client.get_ohlcv("NASDAQ:AAPL", "1D"):
        print(bar.close)

Output:

309.38
311.0
312.41
313.33
...

The stream replays the bars_count window first, then waits for live updates — it does not terminate on its own.

Tune it for long-running pipelines:

from tvkit.api.chart import OHLCV, StreamConnectionError

async with OHLCV(max_attempts=10, base_backoff=2.0, max_backoff=60.0) as client:
    try:
        async for bar in client.get_ohlcv("NASDAQ:AAPL", "1D"):
            print(bar.close)
    except StreamConnectionError:
        print("Stream permanently lost after all attempts")

Output:

309.38
311.0
312.41
313.33
...

Identical while the connection holds. StreamConnectionError is raised only after all 10 attempts are exhausted, printing Stream permanently lost after all attempts.

Symbol Format Reference

Market Example
US Equity NASDAQ:AAPL
Crypto BINANCE:BTCUSDT
Index / Macro INDEX:NDFI

Canonical format: EXCHANGE:SYMBOL. Dash notation (EXCHANGE-SYMBOL) is automatically converted. See concepts/symbols.md for the full reference.

Documentation

Full documentation index → docs/index.md

Getting Started

  • Installation — Python version, uv, pip, source install, verification
  • Quickstart — Four self-contained examples in under 15 lines each
  • First Script — Annotated walkthrough from install to first data fetch

Concepts

Guides

Reference

Architecture

Development

Support

  • FAQ — Symbol formats, bar limits, async requirement, disconnect handling
  • Roadmap — Planned features
  • Why tvkit — Design goals, vs rolling your own WebSocket
  • Limitations — Bar caps, rate limits, data coverage gaps
  • Data Sources — TradingView data origin, real-time vs delayed

Examples

Working scripts in examples/ — clone the repo and run immediately.

Why tvkit

TradingView provides powerful market data but does not offer an official Python SDK. tvkit implements the TradingView WebSocket protocol and provides:

  • A clean async Python API
  • Strong typing via Pydantic
  • Structured OHLCV models
  • High-level data utilities (export, scanners)

Without needing to reverse-engineer the protocol yourself. See docs/why-tvkit.md for the full rationale.

Stability

tvkit is under active development. The public API is expected to remain stable within minor versions. Breaking changes will follow semantic versioning.

Contributing

See CONTRIBUTING.md for the development environment setup, quality gate commands, and pull request process.

Quality gates before every commit:

uv run ruff check .
uv run ruff format .
uv run mypy tvkit/
uv run python -m pytest tests/ -v

License

MIT — see LICENSE

Download files

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

Source Distribution

tvkit-0.14.0.tar.gz (250.4 kB view details)

Uploaded Source

Built Distribution

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

tvkit-0.14.0-py3-none-any.whl (180.7 kB view details)

Uploaded Python 3

File details

Details for the file tvkit-0.14.0.tar.gz.

File metadata

  • Download URL: tvkit-0.14.0.tar.gz
  • Upload date:
  • Size: 250.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for tvkit-0.14.0.tar.gz
Algorithm Hash digest
SHA256 fb673b0a016123a07728f05fb55772d043b2528f3626ec41841ea7490b6ccd22
MD5 d0420a9af9601060be593bfba96fc73a
BLAKE2b-256 f594b045c6b41b948084a5c0231a29029fafd5ed001c9d6e258492131c8b5ce4

See more details on using hashes here.

Provenance

The following attestation bundles were made for tvkit-0.14.0.tar.gz:

Publisher: release.yml on lumduan/tvkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tvkit-0.14.0-py3-none-any.whl.

File metadata

  • Download URL: tvkit-0.14.0-py3-none-any.whl
  • Upload date:
  • Size: 180.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for tvkit-0.14.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4aa97b69b790b39bb43e0bd1cbd936b37d17352ded926b3bb82d174c37be2876
MD5 8ae18b426aaa0f1579b45784d68acd68
BLAKE2b-256 a876a262f6144ac262ba45880478f05233661a4c80444f00e7c6ea36e704b9ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for tvkit-0.14.0-py3-none-any.whl:

Publisher: release.yml on lumduan/tvkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.15.0

2 files

This release

0.14.0 This release

2 files

0.13.1

2 files

0.13.0

2 files

0.12.0

2 files

0.11.2

2 files

0.11.1

2 files

0.11.0

2 files

0.10.0

1 file

0.9.0

2 files

0.8.0

2 files

0.7.0

2 files

0.6.0

2 files

0.5.0

2 files

0.4.0

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page