predictor-api-client

Predictor API client-side application for prediction (RESTful API for predictions via trained models identified by unique IDs)

https://github.com/bdalab/predictor-api-client

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.5%) to scientific vocabulary

Keywords

api-client flask-restful prediction python
Last synced: 6 months ago · JSON representation ·

Repository

Predictor API client-side application for prediction (RESTful API for predictions via trained models identified by unique IDs)

Basic Info
Statistics
  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Topics
api-client flask-restful prediction python
Created over 4 years ago · Last pushed almost 4 years ago
Metadata Files
Readme License Citation

README.md

Predictor API client

GitHub last commit GitHub issues GitHub code size in bytes PyPI - Python Version GitHub top language PyPI - License

This package provides a PyPi-installable lightweight client application for the Predictor API RESTFull server application. The package implements PredictorApiClient class enabling fast and easy method-based calls to all endpoints accessible on the API. To make working with the client a piece of cake, it provides full-documented example scripts for each of the supported endpoints. For more information about the Predictor API, please read the official readme and documentation.

The full programming sphinx-generated docs can be seen in the official documentation.

Endpoints: 1. predictor endpoints (/predict and /predict_proba) 1. /predict - calls .predict on the specified predictor. 2. /predict_proba - calls .predict_proba on the specified predictor. 2. security endpoints (/signup, /login, and /refresh) 1. /signup - signs-up a new user. 2. /login - logs-in an existing user (obtains access and refresh authorization tokens). 3. /refresh - refreshes an expired access token (obtains refreshed authorization access token).

Contents: 1. Installation 2. Configuration 3. Data 4. Examples 5. License 6. Contributors


Installation

pip install predictor-api-client

Configuration

The package provides the following configuration of the PredictorApiClient object during the instantiation: 1. API deployment specific configuration: it supports the configuration of the host (IP address), port (port number), and other settings related to the deployment and operation of the Predictor API (for more information, see the docs/). 2. API client specific configuration: it supports the configuration of the logging (logging_configuration). In this version, the package provides logging of the successful as well as unsuccessful /predict and /predict_proba endpoint calls (for more information, see the docs/).

Data

The full description of the requirements on input/output data (format, shape, etc.) can be found here.

Examples

In general, every time a client is used, the PredictorApiClient class must be instantiated. Next, all endpoint-specific data must be prepared. And finally, the endpoint-specific methods can be called. The full example scripts for each of the supported endpoints are placed at ./examples (simplified examples are shown bellow).

Client instantiation

```python from pprint import pprint from http import HTTPStatus from predictorapiclient.client import PredictorApiClient

Prepare the predictor API client settings

---------------------------------------------

Must be same as for the running Predictor API

---------------------------------------------

1. host (IP address)

2. port (port number)

3. request verification

4. request timeout in seconds

host = "http://127.0.0.1" port = 5000 verify = True timeout = 2

Instantiate the predictor API client

client = PredictorApiClient(host=host, port=port, verify=verify, timeout=timeout) ```

User sign-up

```python

This example assumes the presence of the client instantiation code

TODO: prepare data for a new user (see the API's requirements on the password)

1. username

2. password (e.g. can be generated with https://passwordsgenerator.net/)

username = "" password = ""

print("\n-- [01] example --") print(f"Signing-up a new user with username: {username} and password: {password}\n")

Sign-up a new user

response, statuscode = client.signup(username, password)

Check the output

if statuscode in (HTTPStatus.OK, HTTPStatus.CREATED): print("Successfully signed-up a new user") else: print(f"The request was unsuccessful ({statuscode}): {response}")

print("Response:") pprint(response) ```

User log-in

```python

This example assumes the presence of the client instantiation code

TODO: prepare data for an existing user (data from: user sign-up)

1. username

2. password

username = "" password = ""

print("\n-- [02] example --") print(f"Logging-in an existing user with username: {username} and password: {password}\n")

Log-in an existing user

response, statuscode = client.login(username, password)

Check the output

if statuscode == HTTPStatus.OK: print("Successfully logged-in an existing user") else: print(f"The request was unsuccessful ({statuscode}): {response}")

print("Response:") pprint(response) ```

Expired access token refresh

```python

This example assumes the presence of the client instantiation code

TODO: prepare data for request authorization (refresh token from: user log-in)

refresh_token = ""

print("\n-- [03] example --") print("Refreshing an expired access token\n")

Refresh an expired access token

response, statuscode = client.refreshaccesstoken(refreshtoken)

Check the output

if statuscode == HTTPStatus.OK: print("Successfully refreshed an expired access token") else: print(f"The request was unsuccessful ({statuscode}): {response}")

print("Response:") pprint(response) ```

Prediction

```python

This example assumes the presence of the client instantiation code

import numpy

TODO: prepare data for request authorization (access token and refresh token)

accesstoken = "" refreshtoken = ""

TODO: prepare model identifier

Example:

modelidentifier = "dummypredictor"

model_identifier = ""

TODO: prepare predictor data (feature values/labels)

----------------------------------------------------

Must meet the data requirements of the Predictor API

----------------------------------------------------

Example (10 subjects, each having 100 1-D features):

feature_values = numpy.random.rand(10, 1, 100)

feature_labels = None

featurevalues = "" featurelabels = None

print("\n-- [04] example --") print(f"Calling for prediction(s) on a predictor identified with: {model_identifier}\n")

Make the prediction(s)

Use one of the following:

1. client.predict(...)

2. client.predict_proba(...)

response, statuscode = client.predict( # or client.predictproba(...) accesstoken=accesstoken, refreshtoken=refreshtoken, modelidentifier=modelidentifier, featurevalues=featurevalues, featurelabels=featurelabels)

Check the output

if statuscode == HTTPStatus.OK: print("Successfully called .predict(...)/.predictproba(...)") else: print(f"The request was unsuccessful ({status_code}): {response}")

print("Response:") pprint(response) ```

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributors

This package is developed by the members of Brain Diseases Analysis Laboratory. For more information, please contact the head of the laboratory Jiri Mekyska mekyska@vut.cz or the main developer: Zoltan Galaz galaz@vut.cz.

Owner

  • Name: Brain Diseases Analysis Laboratory
  • Login: BDALab
  • Kind: organization
  • Email: mekyska@vut.cz
  • Location: Brno, Czech Republic

BDALab is an international multidisciplinary research group focusing on the objective and quantitative analysis of brain diseases.

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Galaz"
  given-names: "Zoltan"
  orcid: "https://orcid.org/0000-0002-8978-351X"
- family-names: "Mucha"
  given-names: "Jan"
  orcid: "https://orcid.org/0000-0001-5126-440X"
- family-names: "Zvoncak"
  given-names: "Vojtech"
  orcid: "https://orcid.org/0000-0002-1948-4653"
- family-names: "Mekyska"
  given-names: "Jiri"
  orcid: "https://orcid.org/0000-0002-6195-193X"
title: "Predictor API client"
version: 1.0.1
date-released: 2021-11-26
url: "https://github.com/BDALab/predictor-api-client/"

GitHub Events

Total
Last Year

Committers

Last synced: about 2 years ago

All Time
  • Total Commits: 11
  • Total Committers: 2
  • Avg Commits per committer: 5.5
  • Development Distribution Score (DDS): 0.182
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Zoltán Galáž x****0@g****m 9
Zoltán Galáž z****n@g****u 2
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 7 months ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 16 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 1
  • Total versions: 2
  • Total maintainers: 1
pypi.org: predictor-api-client

Predictor API client

  • Versions: 2
  • Dependent Packages: 0
  • Dependent Repositories: 1
  • Downloads: 16 Last month
Rankings
Dependent packages count: 10.1%
Dependent repos count: 21.6%
Forks count: 29.8%
Average: 31.0%
Stargazers count: 38.8%
Downloads: 54.6%
Maintainers (1)
Last synced: 6 months ago

Dependencies

docs/requirements.txt pypi
  • json-tricks *
  • numpy *
  • requests *