A Python wrapper to Haver Analytics' RESTful API.
Project description
haver ![](https://pypi-camo.freetls.fastly.net/89b062f695223ddae294fea520e2867f28adfb8e/68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f4c7563614d696e676172656c6c692f68617665722f6d61737465722f68617665722f7265732f68617665722e6a7067)
Installation
pip install haver
How to
Connection and Authentication
from haver import Haver
haver = Haver(private_token='<your-haver-API-token>')
The class Haver
also accepts keyword arguments to be passed to requests,
which handles the connection to the API under the hood. In this way,
by passing e.g. verify
and proxy
parameters, users can access Haver databases from behind firewalls.
For example:
haver = Haver(private_token='<your-haver-API-token>',
verify=False, # Or local path to certificates
proxies={'http': 'http://proxy-username:proxy-password@proxy-server.com:8080',
'https': 'http://proxy-username:proxy-password@proxy-server.com:8080'})
Instead of passing the token explicitely each time,
the user can also set an environmental variable HAVER_TOKEN
containing the API token.
In this case connection will be as simple as
haver = Haver()
.
Obtaining tokens
To obtain your token, follow these steps:
- Log into haverview.com, then create a graph with any series.
- Click the vertical dots next to the Directory and Series tabs, above the search box.
- Select Export & Sharing in that menu. This will replace the left tab with the Export dialog.
- Copy the contents of the URL field. It is a link which contains your token, specified as a query parameter
E.g. from
https://api.haverview.com/some/path/here?token=3f15493a-9e05-4b61-93ff-8ba56cb3a726
your token would be 3f15493a-9e05-4b61-93ff-8ba56cb3a726
.
Exploring available resources
All available databases can easily be listed as
haver.get_databases()
which will return a dictionary with keys the database names and values the corresponding database description:
{'UNPOP': 'U.N. Population Statistics',
'EPFRECA': 'Fund Country Allocations',
'EUFIN': 'Financial Data',
...
}
Further information on each dataset can be obtained via the method haver.database_info
,
and series within each database can be listed e.g. as
haver.get_series(database='UNPOP', full_info=True)
In addition, a search function is also available to allow the user to search series by their descriptions, for example as:
haver.search(query='employment')
Querying data
In order to retrieve data, the user has the option of querying one series at a time via the dedicated method
haver.read(database='EUDATA', series='N997CE')
which returns data in dictionary format, or querying multiple series as
haver.read_df(haver_codes=['N997CE@EUDATA','N025CE@EUDATA'])
where individual haver_codes
are created by joining series and database names as {series}@{database}
.
Finally, a database of available recessions can be obtained as
haver.recessions()
Author
Luca Mingarelli, 2024
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.