Metadata-Version: 2.4
Name: bardata
Version: 0.0.9
Summary: Unified api to fetch stock prices from varied sources
Keywords: finance,data
Author: Furechan
Author-email: Furechan <furechan@xsmail.com>
License-Expression: MIT
Classifier: Programming Language :: Python :: 3
Requires-Dist: numpy
Requires-Dist: pandas
Requires-Dist: pyarrow
Requires-Dist: holidays
Requires-Dist: platformdirs
Requires-Dist: typing-extensions>=4.0
Requires-Dist: yfinance ; extra == 'all'
Requires-Dist: tiingo ; extra == 'all'
Requires-Dist: massive ; extra == 'all'
Requires-Dist: massive ; extra == 'massive'
Requires-Dist: polars ; extra == 'polars'
Requires-Dist: tiingo ; extra == 'tiingo'
Requires-Dist: yfinance ; extra == 'yahoo'
Requires-Python: >=3.10
Provides-Extra: all
Provides-Extra: massive
Provides-Extra: polars
Provides-Extra: tiingo
Provides-Extra: yahoo
Description-Content-Type: text/markdown

# Bardata - Common api to fetch stock prices from various sources

This project provides a minimal common api to fetch stock prices from various sources. It includes a driver model with entry points to add custom data source providers. Each driver is implemented as a thin wrapper around the respective client libraries.

> [!WARNING]
> This project is experimental and the interface is likely to change.

## Conventions

- Prices are dataframes with a datetime index called `date` or `datetime`
- Column names `open`, `high`, `low`, `close`, `volume` all **lower case**
- Arguments like `freq`, `start_date`, `end_date` and `max_bars` are optional
- Price data is adjusted by default

## Fetching Prices

```python
from bardata import get_prices

prices = get_prices("AAPL", freq="daily", source="tiingo")  # pandas.DataFrame
```

## Polars Adapters

By default prices are returned as pandas DataFrames. For polars output, use the `bardata.polars` adapters, which mirror the pandas methods but return polars dataframes instead. This requires the `polars` extra `"bardata[polars]"`.

```python
from bardata.polars import get_prices

prices = get_prices("AAPL", freq="daily", source="tiingo")  # polars.DataFrame
```

The pandas index (`date`/`datetime`) becomes an explicit column in the polars dataframe.

## Built-in Data Sources

- `yahoo` — [yfinance](https://yfinance-python.org/)
- `tiingo` — [Tiingo](https://www.tiingo.com/)
- `massive` — [Massive](https://massive.com/)

## Default Source

When `source` is omitted, it is resolved from environment variables depending on frequency — `BARDATA_DEFAULT_ENDOFDAY` for end-of-day data and `BARDATA_DEFAULT_INTRADAY` for intraday (hourly/minute). There is no built-in default: if the default variable is not set, fetching without an explicit `source` will raise an exception.

```shell
export BARDATA_DEFAULT_ENDOFDAY=tiingo
export BARDATA_DEFAULT_INTRADAY=massive
```

## Credentials

Some data sources require credentials
- Tiingo via the `TIINGO_API_KEY` environment variable
- Massive via the `MASSIVE_API_KEY` environment variable

## Installation

You can install the package with pip. Include the required source as an extra: `yahoo`, `tiingo`, `massive`, or `all` for all built-in sources. Add `polars` for polars support.

```shell
pip install "bardata[tiingo,massive,polars]"
```

## Related Projects and Resources

- [yfinance](https://github.com/ranaroussi/yfinance) - Download market data from Yahoo! Finance's API
- [tiingo-python](https://github.com/hydrosquall/tiingo-python) - Python client for interacting with the Tiingo Financial Data API (stock ticker and news data)
- [client-python](https://github.com/massive-com/client-python) - The official Python client library for the Massive.com REST and WebSocket API.
- [pandas-datareader](https://github.com/pydata/pandas-datareader) - Extract data from a wide range of Internet sources into a pandas DataFrame.
- [findatapy](https://github.com/cuemacro/findatapy) - Python library to download market data via Bloomberg, Eikon, Quandl, Yahoo etc.
