Package: fetchable
This is the Fetchable client-side Software Development Kit (SDK) for Python. It allows developers of robots, smart speakers, voice assistants, etc. to quickly develop programs that make calls to the Fetchable API. The library has only been tested on Ubuntu systems so far.Table of ContentsInstallationUsageErrorsContributingLicenseInstallationPre-requisitesPython 2.7 or 3.6An active Fetchable account.Install PackageThe recommended way to install this package is through pip (or pip3) as follows:$pipinstallfetchableSet Up KeysLog into your account and on the console page, download the authentication keys and note the location it downloaded to. The file should be named ‘fetchable_auth_keys.json’. Note: be sure to keep this file secure and share it or commit it to any source control.2. By default, when the library runs it will attempt to read the file containing your keys from an environment variable which
specifies the path to the file (you can also override the environment variable by explicitly setting the path in the constructor). Set the environment variable as so:$exportFETCHABLE_AUTH_FILE=/path/to/fetchable_auth_keys.jsonUsageOnce you have completed the installation, you can start fetching data from the index. The main class used to interact with the API is the FetchableClient object.Constructing the Client ObjectThere are three optional parameters which can be passed to the constructor of the FetchableClient object.API versionThe verison of the API to be used can be specified with theapi_versionparameter. The parameter is an enum defined in the configuration file which needs to be imported. The FetchableClient object will default to the latest version in the absence of this parameter.fromfetchableimportFetchableClientfromfetchableimportconfigurationclient=FetchableClient(api_version=configuration.api_version.v0_1)User agentThe FetchableClient object allows you to set your own user-agent header, this can be done through theuser_agentparameter in the format<custom-user-agent>/<version>whereversiontakes the form0.1.0,0.2.0,1.0.0, etc. By setting this to something relevant to only your application (e.g.my-amazing-chatbot/0.1) and by whitelisting only that value through the console you can enhance the security of your account and distinguish between different applications. The default is value isfetchable-python-client/x.y.z.fromfetchableimportFetchableClientclient=FetchableClient(user_agent='my-amazing-chatbot/0.1.0')Authentication credentialsBy default, the libary will attempt to read your authentication keys from the file specified by theFETCHABLE_AUTH_FILEenvironment variable. You can also specify this through the constructor. If both are set, the value passed through to the constructor will override the  environment variable. If neither are set, an exception is thrown.fromfetchableimportFetchableClientclient=FetchableClient(auth_file='/path/to/file/here.json')Fetching from endpointsOnce the installation has been completed and the object has been constructed, you can begin making calls against the API endpoints. Note: these endpoints only cover version v0.1 of the API, visit theendpointdocumentation for more details on these.API status endpointThis endpoint is useful to test the connection and authentication of the client as well as receive the current status of the API.fromfetchableimportFetchableClientclient=FetchableClient()status_response=client.status()if(status_response['status_code']==200):print("The Fetchable API is up - all systems are go")elif(status_response['status_code']==1001):print("I can't connect to the internet right now...")else:print(status_response)Entity-attribute endpointThis endpoint is used to fetch the attributes of entities in our index.fromfetchableimportFetchableClientclient=FetchableClient()entity_response=client.fetch_entity_attribute("Mount Everest","Elevation")if(entity_response['status_code']==200):print("The height of mount_everest is{}{}.".format(entity_response['value'],entity_response['unit']))elif(entity_response['status_code']==1001):print("Can't connect to the internet right now...")else:print(entity_response)Dictionary endpointUsed to fetch the definitions of words.fromfetchableimportFetchableClientclient=FetchableClient()definition_response=client.fetch_word_definition("ameliorate")if(definition_response['status_code']==200):print("The definition of{}: is{}".format("ameliorate",definition_response['meanings'][0]))elif(definition_response['status_code']==1001):print("Can't connect to the internet right now...")else:print(definition_response)Joke endpointfromfetchableimportFetchableClientclient=FetchableClient()joke_response=client.fetch_joke()if(joke_response['status_code']==200):print("{}-{}".format(joke_response['setup'],joke_response['punchline']))elif(joke_response['status_code']==1001):print("Can't connect to the internet right now...")else:print(joke_response)Inspirational quote endpointfromfetchableimportFetchableClientclient=FetchableClient()quote_response=client.fetch_quote()if(quote_response['status_code']==200):print("{}by{}".format(quote_response['quote'],quote_response['author']))elif(quote_response['status_code']==1001):print("Can't connect to the internet right now...")else:print(quote_response)Fun fact endpointfromfetchableimportFetchableClientclient=FetchableClient()fun_fact_response=client.fetch_fun_fact()if(fun_fact_response['status_code']==200):print(fun_fact_response['fun_fact'])elif(fun_fact_response['status_code']==1001):print("Can't connect to the internet right now...")else:print(fun_fact_response)Exact endpointThis endpoint allows you to specify an exact endpoint to fetch.fromfetchableimportFetchableClientclient=FetchableClient()endpoint_response=client.fetch_endpoint("/v0.1/mount_everest/height")if(endpoint_response['status_code']==200):print("The height of mount_everest is{}{}s.".format(endpoint_response['value'],endpoint_response['unit']))elif(endpoint_response['status_code']==1001):print("Can't connect to the internet right now...")else:print(endpoint_response)ErrorsExceptionsThe FetchableClient object will throw exceptions when:The path to the authentication file is not set through an environment variable or constructor argument.The path to the authentication file is not a valid file path.The authentication file is not formatted properly.Functions taking string parameters are passed arguments which are not strings.Error codesThere are two types of error codes you can receive back from the client object. Those in the 1xxx range are errors thrown by the client object itself and other error codes in the 2xx, 3xx, 4xx and 5xx ranges are the standard http error codes received from the server. For more information on the server error codes visit thedocumentation.CodeDescriptionReason1001Connection errorThe client cannot make a connection to the API server.1002Timeout errorThe request timed out.1003Proxy errorA proxy error occurred.1004Unknown errorAn unknown error occurred.ContributingContributions are welcome and encouraged! See theContributing Guidefor information on how to contribute.LicenseLicensed under Apache Version 2.0.See theLICENSEfile for more information.