Skip to main content

A helper package for preparing and sending requests towards the TVB REST API

Project description

TVB REST client

The tvb-rest-client is a helper package built with the intention to simplify a Python client interaction with TVB REST Server. All the logic necessary to prepare and send requests towards the REST server, is embedded under this client API.

GET requests are sent from this python client using the requests library.

For the POST requests, a client has to attach a file with some input configuration. Such a file is usually an H5 in TVB specific format. Thus, tvb-rest-client has all the logic for preparing those H5 files and sending requests. Also, the REST server uses a Keycloak client at log in time, so this client will open a browser that allows the user to log in, before attempting to make the requests.

Usage

You should have a TVB REST server running, or access to a public one. Then into tvb-rest-client you need to provide the URL towards this TVB REST server. For the following example, we will suppose TVB REST server runs on http://localhost:9090

To launch a TVB REST server locally, you should download tvb-framework version >2.0. and launch it:

$ python -m tvb.interfaces.rest.server.run   # Launch TVB REST server locally

Accessing the client API entry-point

If the TVB REST server you want to access runs at another address, change the parameter in the bellow TVBClient instantiation.

from tvb.interfaces.rest.client.tvb_client import TVBClient
tvb_client = TVBClient("http://localhost:9090")

Attempt to login and start using the client API to send requests, by calling different types of methods:

  • methods that return a list of DTOs

tvb_client.browser_login()
list_of_user_projects = tvb_client.get_project_list()
list_of_datatypes_in_project = tvb_client.get_data_in_project(list_of_user_projects[0].gid)
list_of_operations_for_datatype = tvb_client.get_operations_for_datatype(list_of_datatypes_in_project[0].gid)
  • method that download data files locally, under a folder chosen by the client

datatype_path = tvb_client.retrieve_datatype(list_of_datatypes_in_project[0].gid, download_folder)
  • method that loads in memory the datatype downloaded previously

datatype = tvb_client.load_datatype_from_file(datatype_path)
  • methods that launch operations in the TVB server

    Such an operation requires the client to prepare the operation configuration and send it in an H5 file together with the requests.

    By using the client API, the user only needs to instantiate the proper Model class and send it as argument to the following method. It wraps the serialization of the Model inside the H5 and the attaching to the POST request.

    The example above launches a Fourier analyzer, we suppose the Fourier AlgorithmDTO is list_of_operations_for_datatype[0].

from tvb.adapters.analyzers.fourier_adapter import FFTAdapterModel, FourierAdapter

project_gid = list_of_user_projects[0].gid
model = FFTAdapterModel()
# logic to fill the model with required attributes
operation_gid = tvb_client.launch_operation(project_gid, FourierAdapter, model)
  • method to monitor the status of an operation

monitor_operation(tvb_client, operation_gid)

Acknowledgments

This project has received funding from the European Union’s Horizon 2020 Framework Programme for Research and Innovation under the Specific Grant Agreement Nos. 785907 (Human Brain Project SGA2), 945539 (Human Brain Project SGA3) and VirtualBrainCloud 826421.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tvb-rest-client-2.9.tar.gz (412.9 kB view details)

Uploaded Source

Built Distribution

tvb_rest_client-2.9-py3-none-any.whl (745.0 kB view details)

Uploaded Python 3

File details

Details for the file tvb-rest-client-2.9.tar.gz.

File metadata

  • Download URL: tvb-rest-client-2.9.tar.gz
  • Upload date:
  • Size: 412.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.19

File hashes

Hashes for tvb-rest-client-2.9.tar.gz
Algorithm Hash digest
SHA256 c41899b39eed8488b23012be46c442cc47844895607cb3300561c37c190fc276
MD5 85f0f84aff000a8ba4508b28037ae5c9
BLAKE2b-256 3ec3e07749df3b67e45d8def7f5c2cfe84de2af17562722e03952703665e9b56

See more details on using hashes here.

File details

Details for the file tvb_rest_client-2.9-py3-none-any.whl.

File metadata

File hashes

Hashes for tvb_rest_client-2.9-py3-none-any.whl
Algorithm Hash digest
SHA256 329b0a73448c62306183cb149b3e892145ee45585dd400261b27bb9c72ec6a8a
MD5 24e1aae0a2bfe3c176256f9c493a9680
BLAKE2b-256 a40cff432d73f90efd8943124bedab4d79ada08effee20d1e58fc1ebadea72ed

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page