Library to use the Spinque Query API in your Python project.
The Spinque Query API is an HTTP API to retrieve search results for queries. Also check out the documentation of the Spinque Query API.
Using PyPi:
$ pip install spinque-query-api
For documentation on the Spinque Query API itself, please see this.
from spinque_query_api import Api, Query
from spinque_query_api.types import RequestType
api = Api(
workspace='playground',
config='default',
api='test'
)
query = Query(endpoint='search', parameters=[('q', 'test')])
options = {'count': 20, 'dev_version': 'master'}
print(api.fetch(query, options))
# or a statistics call:
print(api.fetch(query, options, RequestType.STATISTICS))
Some Spinque APIs require authentication using OAuth 2.0. Support for the Client Credentials flow (for server applications) is provided through this library:
from spinque_query_api import Api, Query, Authentication
api = Api(
workspace='demo08',
config='default',
api='demo',
authentication=Authentication()
)
queries = [
Query(endpoint='test', parameters=[])
]
print(api.fetch(queries))
A Client ID and Client Secret can be generated by creating a new System-to-System account in the Settings > Team Members section of Spinque Desk.
These can then be added in a spinque.config
file that the Authentication module can work this. For more info about this, see the Spinque documentation.
If you do not want to store your credentials in such a file, because they are retrieved from somewhere else you can provide them as direct parameters as well:
from spinque_query_api import Api, Authentication
api = Api(
workspace='demo08',
config='default',
api='demo',
authentication=Authentication(client_id="ID", client_secret="SECRET")
)