Skip to main content

tvkit is a Python library that fetches real-time stock data from TradingView, including price, market cap, P/E ratio, ROE, and more for stocks from multiple countries. Easily access and analyze financial metrics for global markets.

Project description

tvkit

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

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
  • Historical data retrieval by bar count or explicit date range
  • 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)
        # 2024-01-10 00:00:00  189.34

asyncio.run(main())

See more working examples in examples/.

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

Project details


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.4.0.tar.gz (93.2 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.4.0-py3-none-any.whl (80.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tvkit-0.4.0.tar.gz
  • Upload date:
  • Size: 93.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for tvkit-0.4.0.tar.gz
Algorithm Hash digest
SHA256 7a25062e9a52fad067bba7a18a329b63f1491ef42f61476d46099848fb63af9b
MD5 83c37ece8dd99b6d7eeb85a926796bde
BLAKE2b-256 36f60690f256d4510e3c32310d5a626ede614df774df69558dc2905e3a1d15f8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tvkit-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 80.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for tvkit-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6baf764e12a9193f88dfd646e9f2e964d5cefe9c292cb264ccf4a84d890656af
MD5 99e8cf1fde51357d1c6261764b04879a
BLAKE2b-256 5b646dd4b8e1b9ff728a81dbda6846309ae7f78656cfd25570057d3289a6ef48

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page