Skip to main content

Drop-in yfinance wrapper with DuckDB OHLCV caching

Project description

dyfinance

CI PyPI Python License

Drop-in replacement for yfinance with DuckDB OHLCV caching. Generated by Claude.

# Change just this one line
import dyfinance as yf

ticker = yf.Ticker("AAPL")
df = ticker.history(period="1mo")  # cached transparently

Why DuckDB?

Most caching solutions for market data use SQLite, CSV, or Parquet files. dyfinance uses DuckDB because it is fundamentally better suited for financial time-series data:

  • Columnar storage -- analytical queries (filtering by date range, aggregating OHLCV columns) run orders of magnitude faster than row-oriented SQLite
  • Single file, zero config -- like SQLite, DuckDB is an embedded database with no server process; your entire cache lives in one ~/.dyfinance/cache.duckdb file
  • Native pandas integration -- DuckDB reads and writes DataFrames without serialization overhead
  • Your cache is a database -- you can query the cache directly with SQL for custom analysis beyond what yfinance offers:
import duckdb

conn = duckdb.connect("~/.dyfinance/cache.duckdb")
# Your own analysis — no yfinance API limits
conn.sql("""
    SELECT ticker, interval,
           MIN(ts) AS first_date, MAX(ts) AS last_date,
           COUNT(*) AS rows
    FROM ohlcv
    GROUP BY ticker, interval
""").show()

Features

  • 100% yfinance-compatible -- same API signatures, defaults, and output structures
  • Transparent DuckDB caching -- daily+ OHLCV data is cached locally; redundant fetches are eliminated
  • Full fallback -- any attribute or method not overridden by dyfinance is delegated to yfinance
  • Spot-check validation -- stale cache is automatically verified against fresh data and corrected if needed

Installation

pip install dyfinance

Requires Python >= 3.10.

Quick Start

import dyfinance as yf

# Single ticker
aapl = yf.Ticker("AAPL")
hist = aapl.history(period="6mo")           # first call fetches, subsequent calls use cache
info = aapl.info                            # delegated to yfinance

# Multiple tickers
data = yf.download(["AAPL", "MSFT"], period="1mo")

# All yfinance features work as-is
aapl.dividends
aapl.financials
aapl.options

Cached Intervals

Cached (DuckDB) Passthrough (yfinance direct)
1d, 5d, 1wk, 1mo, 3mo 1m, 2m, 5m, 15m, 30m, 60m, 90m, 1h

Known Limitations

  • ISIN codes are not supported in the cached path. yfinance's download() auto-converts ISIN codes (e.g. US0378331005) to ticker symbols, but dyfinance skips this conversion for cacheable intervals. Use ticker symbols directly (e.g. AAPL instead of US0378331005).

Configuration

Environment Variable Default Description
DYFINANCE_DB_PATH ~/.dyfinance/cache.duckdb Cache database file path
DYFINANCE_STALE_HOURS 6 Hours before spot-check fires

Cache Management

import dyfinance as yf

# Clear cache for a specific ticker
yf.Ticker("AAPL").clear_cache()        # all intervals
yf.Ticker("AAPL").clear_cache("1d")    # daily only

Development

pip install -e ".[dev]"

make test        # offline tests
make test-live   # live yfinance comparison tests (network required)
make lint        # ruff check
make typecheck   # mypy strict
make clean       # remove caches and build artifacts

License

Apache-2.0

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

dyfinance-0.1.0.tar.gz (42.3 kB view details)

Uploaded Source

Built Distribution

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

dyfinance-0.1.0-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

Details for the file dyfinance-0.1.0.tar.gz.

File metadata

  • Download URL: dyfinance-0.1.0.tar.gz
  • Upload date:
  • Size: 42.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dyfinance-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ee6123ca41ba88123e7a73b08b8bd8323f9b61fc04a4758665a3613526365d45
MD5 5736fcbba5a204b9cc9ab6f869f7e757
BLAKE2b-256 fd741678566f4ebcb4301981a05920944c4292ef87f95f48e95d1bcddbced682

See more details on using hashes here.

Provenance

The following attestation bundles were made for dyfinance-0.1.0.tar.gz:

Publisher: publish.yml on Qooh0/dyfinance

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

File details

Details for the file dyfinance-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dyfinance-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dyfinance-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d7ac7f0ea7343f71772afb0d35a42a0ae54bdc14b6bae10547820e907007bc10
MD5 d70c1b7651d283b8671907e6cb20c74e
BLAKE2b-256 4e62dfe942886d588bc1c6101ed9c33910232d4fc98c304237210cb162cce9df

See more details on using hashes here.

Provenance

The following attestation bundles were made for dyfinance-0.1.0-py3-none-any.whl:

Publisher: publish.yml on Qooh0/dyfinance

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

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