Skip to content

Commit 659233a

Browse files
author
Dario Varotto
committed
Datafile queries can be tagged
1 parent a0e0599 commit 659233a

File tree

5 files changed

+139
-17
lines changed

5 files changed

+139
-17
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ A Python library to consume the [RavenPack API](https://www.ravenpack.com).
1414
The Python client helps managing the API calls to the RavenPack dataset server
1515
in a Pythonic way, here are some examples of usage, you can find more in the tests.
1616

17-
This is still a work in progress: while the API is stable we are still working
18-
on this Python wrapper.
17+
#### Note
18+
19+
This is still a work in progress.
20+
The API is stable and we are continuing to update this Python wrapper.
1921

2022
## Usage
2123

README.rst

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
RavenPack API - Python client
2+
=============================
3+
4+
A Python library to consume the `RavenPack
5+
API <https://www.ravenpack.com>`__.
6+
7+
`API documention. <https://www.ravenpack.com/support/>`__
8+
9+
Installation
10+
------------
11+
12+
::
13+
14+
pip install ravenpackapi
15+
16+
About
17+
-----
18+
19+
The Python client helps managing the API calls to the RavenPack dataset
20+
server in a Pythonic way, here are some examples of usage, you can find
21+
more in the tests.
22+
23+
Note
24+
^^^^
25+
26+
This is still a work in progress. The API is stable and we are
27+
continuing to update this Python wrapper.
28+
29+
Usage
30+
-----
31+
32+
First, you'll need an API object that will deal with the API calls.
33+
34+
You will need a RavenPack API KEY, you can set the ``RP_API_KEY``
35+
environment variable or set it in your code:
36+
37+
.. code:: python
38+
39+
from ravenpackapi import RPApi
40+
41+
api = RPApi(api_key="YOUR_API_KEY")
42+
43+
Getting data from the datasets
44+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45+
46+
There are several models to deal with data, the datasets are a cut of
47+
the RavenPack data they are defined with a set of filters and a set of
48+
fields.
49+
50+
.. code:: python
51+
52+
# Get the dataset description from the server, here we use 'us30'
53+
# one of RavenPack public datasets with the top30 companies in the US
54+
55+
ds = api.get_dataset(dataset_id='us30')
56+
57+
Downloads: json
58+
^^^^^^^^^^^^^^^
59+
60+
.. code:: python
61+
62+
data = ds.json(
63+
start_date='2018-01-05 18:00:00',
64+
end_date='2018-01-05 18:01:00',
65+
)
66+
67+
for record in data:
68+
print(record)
69+
70+
The json endpoint is handy for asking data synchronously, if you need to
71+
download big data chunks you may want to use the asynchronous datafile
72+
endpoint instead.
73+
74+
Json queries are limited to \* granular datasets: 10,000 records \*
75+
indicator datasets: 500 entities, timerange 1Y, lookback 1Y
76+
77+
Downloads: datafile
78+
^^^^^^^^^^^^^^^^^^^
79+
80+
For bigger requests the datafile endpoint can be used.
81+
82+
Requesting a datafile, will give you back a job promise, that will take
83+
some time to complete.
84+
85+
.. code:: python
86+
87+
job = ds.request_datafile(
88+
start_date='2018-01-05 18:00:00',
89+
end_date='2018-01-05 18:01:00',
90+
)
91+
92+
with open('output.csv') as fp:
93+
job.save_to_file(filename=fp.name)
94+
95+
Entity reference
96+
~~~~~~~~~~~~~~~~
97+
98+
The entity reference endpoint give you all the available information
99+
over an Entity starting from the RP\_ENTITY\_ID
100+
101+
.. code:: python
102+
103+
ALPHABET_RP_ENTITY_ID = '4A6F00'
104+
105+
references = api.get_entity_reference(ALPHABET_RP_ENTITY_ID)
106+
107+
# show all the names over history
108+
for name in references.names:
109+
print(name.value, name.start, name.end)
110+
111+
# print all the ticket valid today
112+
for ticker in references.tickers:
113+
if ticker.is_valid():
114+
print(ticker)

ravenpackapi/models/dataset.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,21 @@ def json(self,
131131
def request_datafile(self, start_date, end_date,
132132
output_format='csv',
133133
compressed=False,
134+
tags=None,
134135
notify=False):
135136
api = self.api
137+
data = {
138+
"start_date": start_date,
139+
"end_date": end_date,
140+
"format": output_format,
141+
"compressed": compressed,
142+
"notify": notify,
143+
}
144+
if tags:
145+
data['tags'] = tags
136146
response = api.request(
137147
endpoint="/datafile/%s" % self.id,
138-
data={
139-
"start_date": start_date,
140-
"end_date": end_date,
141-
"format": output_format,
142-
"compressed": compressed,
143-
"notify": notify,
144-
},
148+
data=data,
145149
method='post',
146150
)
147151
job = Job(api=self.api,

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ pytest-xdist
88
tox
99

1010
coverage
11+
pandoc

setup.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
from setuptools import setup
1+
from setuptools import setup, find_packages
2+
3+
with open('README.rst') as readme_file:
4+
readme = readme_file.read()
25

36
setup(
47
name='ravenpackapi',
5-
version='1.0.2',
6-
packages=['ravenpackapi'],
8+
version='1.0.6',
9+
packages=find_packages(include=['ravenpackapi']),
10+
include_package_data=True,
11+
712
url='https://github.com/RavenPack/python-api',
813
license='MIT',
14+
long_description=readme,
915
author='RavenPack',
1016
author_email='dvarotto@ravenpack.com',
1117
description='RavenPack API - Python client',
@@ -23,11 +29,6 @@
2329

2430
# Pick your license as you wish (should match "license" above)
2531
'License :: OSI Approved :: MIT License',
26-
27-
# Specify the Python versions you support here. In particular, ensure
28-
# that you indicate whether you support Python 2, Python 3 or both.
29-
'Programming Language :: Python :: 2.7',
30-
'Programming Language :: Python :: 3.6.4',
3132
],
3233

3334
keywords='python analytics api rest news data',

0 commit comments

Comments
 (0)