Skip to main content

Python module to get stock data from the Alpha Vantage Api

Project description

# alpha_vantage

[![Build Status](](

*Python module to get stock data from the Alpha Vantage API*

Alpha Vantage delivers a free API for real time financial data and most used finance indicators in a simple json format. This module implements a python interface to the free API provided by Alpha
Vantage ( It requires a free API, that can be requested on

## Install
To install the package use:
pip install alpha_vantage

If you want to install from source, then use:
git clone
pip install -e alpha_vantage

## Usage
To get data in a python, simply import the library and call the object with your api key and get ready for some awesome free realtime finance data.
from alpha_vantage.api_calls.timeseries import TimesSeries
ts = TimesSeries(key='YOUR_API_KEY')
# Get json object with the intraday data and another with the call's metadata
data, meta_data = ts.get_intraday('GOOGL')
Internally there is a retries counter, that can be used to minimize connection errors (in case that the api is not able to respond in time), the default is set to
3 but can be increased or decreased whenever needed.
ts = TimesSeries(key='YOUR_API_KEY',retries='YOUR_RETRIES')
Finally the library supports giving its results as json dictionaries (default) or as pandas dataframe, simply pass the parameter output_format='pandas' to change
the format of the output for all the api calls.
ts = TimesSeries(key='YOUR_API_KEY',output_format='pandas')

## Plotting
Using pandas support we can plot the intra-minute value for 'MSFT' stock quite easily:

from alpha_vantage.api_calls.timeseries import TimesSeries
import matplotlib.pyplot as plt

ts = TimesSeries(key='YOUR_API_KEY', output_format='pandas')
data, meta_data = ts.get_intraday(symbol='MSFT',interval='1min', outputsize='full')
plt.title('Intraday Times Series for the MSFT stock (1 min)')
Giving us as output:
![alt text](images/docs_ts_msft_example.png?raw=True "MSFT minute value plot example")

The same way we can get pandas to plot technical indicators like
bollinger Bolliger Bands®

from alpha_vantage.api_calls.techindicators import TechIndicators
import matplotlib.pyplot as plt

ts = TechIndicators(key='YOUR_API_KEY', output_format='pandas')
data, meta_data = ti.get_bbands(symbol='MSFT', interval='60min', time_period=60)
plt.title('BBbands indicator for MSFT stock (60 min)')
Giving us as output:
![alt text](images/docs_ti_msft_example.png?raw=True "MSFT minute value plot example")

## Tests

In order to run the tests you have to first export your API key so that the test can use it to run.
cd alpha_vantage

## Documentation
To find out more about the available api calls, visit the alpha-vantage documentation at

## Coming soon:
1. ~~Add basic functionality: 0.0.1~~
2. ~~Add retry in order to allow the calls to be retried in case of failure: 0.0.2~~
3. ~~Implement all functions described in the alpha vantage documentation 0.0.3~~
4. ~~Re-factor functions to have an unified method for accessing the api 0.1.0~~
5. ~~Add pandas support through decorators 0.1.2~~
6. ~~Publish on pipy 0.1.3~~
7. Add logging to tests to store api call duration 1.0.1
8. Add unit tests for all the function parameters in the module 1.0.2

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for alpha-vantage, version 0.1.6
Filename, size File type Python version Upload date Hashes
Filename, size alpha_vantage-0.1.6.tar.gz (9.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page