Package: ravenpackapi
A Python library to consume theRavenPackAPI.API documentation.Installationpip install ravenpackapiAboutThe Python client helps managing the API calls to the RavenPack dataset
server in a Pythonic way, here are some examples of usage, you can find
more in the tests.UsageIn order to be able to use the RavenPack API you will need an API KEY.
If you don’t already have one please contact yourcustomer
supportrepresentative.To begin using the API you will need to instantiate an API object that
will deal with the API calls.Using your RavenPack API KEY, you can either set theRP_API_KEYenvironment variable or set it in your code:fromravenpackapiimportRPApiapi=RPApi(api_key="YOUR_API_KEY")Creating a new datasetTo create a dataset you can call thecreate_datasetmethod of the
API with a Dataset instance.fromravenpackapiimportDatasetds=api.create_dataset(Dataset(name="New Dataset",filters={"relevance":{"$gte":90}},))print("Dataset created",ds)Getting data from the datasetsIn the API wrapper, there are several models that maybe used for
interacting with data.Here is how you may get a dataset definition for a pre-existing dataset# Get the dataset description from the server, here we use 'us30'# one of RavenPack public datasets with the top30 companies in the USds=api.get_dataset(dataset_id='us30')Downloads: jsonThe json endpoint is useful for asking data synchronously, optimized for
small requests, if you need to download big data chunks you may want to
use the asynchronous datafile endpoint instead.data=ds.json(start_date='2018-01-05 18:00:00',end_date='2018-01-05 18:01:00',)forrecordindata:print(record)Json queries are limited togranular datasets: 10,000 recordsindicator datasets: 500 entities, timerange 1 year, lookback window 1
yearDownloads: datafileFor bigger requests the datafile endpoint can be used to prepare a
datafile asynchronously on the RavenPack server for later retrieval.Requesting a datafile, will give you back a job object, that will take
some time to complete.job=ds.request_datafile(start_date='2018-01-05 18:00:00',end_date='2018-01-05 18:01:00',)withopen('output.csv')asfp:job.save_to_file(filename=fp.name)Streaming real-time dataIt is possible to subscribe to a real-time stream for a dataset.Once you create a streaming connection to the real-time feed with your
dataset, you will receive analytics records as soon as they are
published.It is suggested to handle possible disconnection with a retry policy.
You can find areal-time streaming example
here.The Result object handles the conversion of various fields into the
appropriate type, i.e.record.timestamp_utcwill be converted todatetimeEntity mappingThe entity mapping endpoint allow you to find the RP_ENTITY_ID mapped
to your universe of entities.universe=["RavenPack",{'ticker':'AAPL'},{# Amazon, specifying various fields"client_id":"12345-A","date":"2017-01-01","name":"Amazon Inc.","entity_type":"COMP","isin":"US0231351067","cusip":"023135106","sedol":"B58WM62","listing":"XNAS:AMZN"},]mapping=api.get_entity_mapping(universe)# in this case we match everythingassertlen(mapping.matched)==len(universe)assert[m.nameforminmapping.matched]==["RavenPack Ltd.","Apple Inc.","Amazon.com Inc."]Entity referenceThe entity reference endpoint give you all the available information for
an Entity given the RP_ENTITY_IDALPHABET_RP_ENTITY_ID='4A6F00'references=api.get_entity_reference(ALPHABET_RP_ENTITY_ID)# show all the names over historyfornameinreferences.names:print(name.value,name.start,name.end)# print all the ticket valid todayfortickerinreferences.tickers:ifticker.is_valid():print(ticker)Training DatasetsAnalyse your own content using RavenPack’s proprietary NLP technology.The API for analyzing your internal content is still in beta and may
change in the future. You can request an early access andsee an
example of usage here.Accessing the low-level requestsRavenPack API wrapper is using therequests
libraryto do HTTPS requests, you can
set common requests parameters to all the outbound calls by setting thecommon_request_paramsattribute.For example, to disable HTTPS certificate verification and to setup your
internal proxy:api=RPApi()api.common_request_params.update(dict(proxies={'https':'http://your_internal_proxy:9999'},verify=False,))# use the api to do requestsPS. For setting your internal proxies, requests will honor the
HTTPS_PROXY environment variable.