Drop-in yfinance wrapper with DuckDB OHLCV caching
Project description
dyfinance
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.duckdbfile - 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.AAPLinstead ofUS0378331005).
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee6123ca41ba88123e7a73b08b8bd8323f9b61fc04a4758665a3613526365d45
|
|
| MD5 |
5736fcbba5a204b9cc9ab6f869f7e757
|
|
| BLAKE2b-256 |
fd741678566f4ebcb4301981a05920944c4292ef87f95f48e95d1bcddbced682
|
Provenance
The following attestation bundles were made for dyfinance-0.1.0.tar.gz:
Publisher:
publish.yml on Qooh0/dyfinance
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dyfinance-0.1.0.tar.gz -
Subject digest:
ee6123ca41ba88123e7a73b08b8bd8323f9b61fc04a4758665a3613526365d45 - Sigstore transparency entry: 992225554
- Sigstore integration time:
-
Permalink:
Qooh0/dyfinance@68e43e6f0324675ae85d37977df92f74ce5f6816 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Qooh0
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@68e43e6f0324675ae85d37977df92f74ce5f6816 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7ac7f0ea7343f71772afb0d35a42a0ae54bdc14b6bae10547820e907007bc10
|
|
| MD5 |
d70c1b7651d283b8671907e6cb20c74e
|
|
| BLAKE2b-256 |
4e62dfe942886d588bc1c6101ed9c33910232d4fc98c304237210cb162cce9df
|
Provenance
The following attestation bundles were made for dyfinance-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on Qooh0/dyfinance
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dyfinance-0.1.0-py3-none-any.whl -
Subject digest:
d7ac7f0ea7343f71772afb0d35a42a0ae54bdc14b6bae10547820e907007bc10 - Sigstore transparency entry: 992225561
- Sigstore integration time:
-
Permalink:
Qooh0/dyfinance@68e43e6f0324675ae85d37977df92f74ce5f6816 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Qooh0
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@68e43e6f0324675ae85d37977df92f74ce5f6816 -
Trigger Event:
push
-
Statement type: