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

Metadata

Release files for tvkit 0.18.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tvkit 0.18.0
File Size Uploaded Provenance
tvkit-0.18.0.tar.gz 269.2 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for tvkit 0.18.0
File Interpreter ABI Platform
tvkit-0.18.0-py3-none-any.whl Python 3 none any Details

Total release size: 455.5 kB

Release files / tvkit-0.18.0.tar.gz

Download URL tvkit-0.18.0.tar.gz
Size 269.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e349ef6ac98e84eb0d7312b5eedd86d3ae9fa800835135291a30bf6734f292fc
BLAKE2b-256 checksum
How to use checksums
d5c88aa290e082c70e15e5f1d78b53438fc202d18433627e835305e5d105c019
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Release files / tvkit-0.18.0-py3-none-any.whl

Download URL tvkit-0.18.0-py3-none-any.whl
Size 186.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c2597fa482f665a1db7c6fa3ffb0fa8ee0405253968dfa86974b62ac89335fa1
BLAKE2b-256 checksum
How to use checksums
e111c30928c928659483d50c0a2d65befcd2a4c455c8d4cde7ed9d4057735e7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Security for tvkit 0.18.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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for tvkit-0.18.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

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.

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