Metadata-Version: 2.4
Name: finquotes
Version: 0.74.1
Summary: Retrieves financial quotes from the web
Author: elmotec
Author-email: elmotec@gmx.com
License-Expression: GPL-3.0
Keywords: stock,quote,quotes,financial,finance,share,common,market
Classifier: Development Status :: 4 - Beta
Classifier: Topic :: Office/Business :: Financial :: Investment
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Requires-Python: <3.16,>=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: beautifulsoup4>=4.10.0
Requires-Dist: click>=8.0.3
Requires-Dist: python-dateutil>=2.8.2
Requires-Dist: lxml>=5.3
Requires-Dist: requests>=2.27
Requires-Dist: requests-cache>=0.9.1
Requires-Dist: yahooquery>=2.3
Requires-Dist: yfinance>=0.2.54
Requires-Dist: edgartools>=5.26.1
Requires-Dist: pandas>=2.0.0
Requires-Dist: pandas-datareader>=0.10.0
Requires-Dist: setuptools>=70.0.0
Dynamic: license-file

[![pipeline status](https://gitlab.com/elmotec/finquotes/badges/main/pipeline.svg)](https://gitlab.com/elmotec/finquotes/-/commits/main)
[![coverage report](https://gitlab.com/elmotec/finquotes/badges/main/coverage.svg)](https://gitlab.com/elmotec/finquotes/-/commits/main)
[![PyPI version](https://badge.fury.io/py/finquotes.svg)](https://badge.fury.io/py/finquotes)
[![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue.svg)](https://www.python.org/downloads/)
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)

# FinQuotes

FinQuotes is a small Python library to be used as a facade to fetch financial data from public sources through a single, consistent interface.  It adapts various interface to a consistent one described below allowing one to quickly switch between service.

It supports close snapshots, historical OHLCV, distributions (dividends), splits, and security metadata across multiple providers (Yahoo Finance, yfinance, yahooquery, Stooq, Morningstar, Quandl, Twelve Data).

- Python: 3.11–3.15
- License: GPL-3.0

## Features

- Unified API and CLI for multiple data sources
- Normalized data models: Price, Distribution, Split, Security
- Deterministic CSV output for easy piping and testing
- Robust network options: retry, timeout, max retries
- Pluggable sources via lightweight “feed” builders

## Install

```sh
python -m pip install finquotes
```

## Quick start (Python)

Use typed builder helpers for clarity, or `build_feed` with a `FeedType`.

```python
import finquotes as fq

# Historical OHLCV (yfinance)
hfeed = fq.build_historical_feed("finquotes.yfinance", auto_adjust=True)
for p in hfeed.fetch_hist_prices("MSFT", begin_date=fq.today(), end_date=fq.today()):
    assert p.open is not None and p.high is not None and p.low is not None

# Distributions & splits (yahooquery)
qhist = fq.build_historical_feed("finquotes.yahooquery")
for d in qhist.fetch_hist_dists("BIL", begin_date=fq.today(), end_date=fq.today()):
    print(d)
for s in qhist.fetch_hist_splits("AAPL", begin_date=fq.today(), end_date=fq.today()):
    print(s)
```

Network parameters (`timeout`, `max_retries`, `retry_delay`, and provider-specific args) can be passed to feed builders as keyword arguments.

## API keys

Some providers require an API key (e.g., Quandl, Twelve Data). FinQuotes looks for keys in:

1) Environment variable: `FINQUOTES_<PROVIDER>_API_KEY` (e.g. `FINQUOTES_QUANDL_API_KEY`)
2) File: `~/.finquotes/api_keys.txt` with lines like:

```text
finquotes.quandl=<YOUR_KEY>
finquotes.twelvedata=<YOUR_KEY>
```

On Windows the file path expands to `%USERPROFILE%\.finquotes\api_keys.txt`.

You can also pass `--api-key` on the CLI or `api_key="..."` to feed builders where applicable.

## Data model at a glance

- `Price(symbol, date|datetime, close[, open, high, low, volume, source])`
- `Distribution(symbol, ex_date, amount[, pay_date])`
- `Split(symbol, ex_date, new_quantity, old_quantity)` and `Split.from_ratio(...)`
- `Security(symbol, name[, type, currency, exchange, country, sector, industry, source, source_id])`

Instances print to CSV for easy piping; attributes are typed (Decimal for prices) and validated by a helper (`PriceValidator`).

## Tips & caveats

- Some providers adjust historical series (e.g., Stooq distributions are adjusted); check source notes before using for cash-flow analysis.
- Yahoo-derived OHLC fields may be dividend-adjusted; see in-code comments where noted.
- Timezone defaults to America/New_York for timestamp parsing.

## Development

Install [uv](https://docs.astral.sh/uv/getting-started/installation/) and sync the locked development environment:

```sh
uv sync --locked
```

Run the local checks:

```sh
make lint
make unit-test
make coverage
make test-all
```

`make test-all` runs unit tests on the Python versions listed in the `pyproject.toml` classifiers. Update those classifiers when support changes; they also drive the GitLab version checks. uv downloads missing interpreters as needed.

Pre-commit hooks:

```sh
uv run --locked pre-commit install
make pre-commit
```

Edit `pyproject.toml` and run `uv lock` when dependencies change. Commit the project file and `uv.lock` together. `make upgrade` refreshes locked dependencies and pre-commit hooks, and `make build` builds the package.

### Publishing (maintainers)

```sh
make release           # bump version, update changelog and lockfile, create tag
git push && git push --tags
```

The tagged `publish-pypi` pipeline job builds the distributions and uploads them to PyPI via trusted
publishing.
