NIH SPARC Python Client
Project description
sparc.client
NIH SPARC Python Client
Architecture details
The sparc.client Python Client stores its configuration in the config.ini file.
The modules of sparc.client are to be defined in services/ directory and need to be derived from BaseService class (services/_default.py) This means that they need to implement the specific functions defined in the interface, such as init, connect(), info(), get_profile(), set_profile() and close(). Apart from that functions, each module in the services may define their own methods (e.g. refer to services/pennsieve.py list_datasets()).
config.ini
The configuration file has the following format:
[global]
default_profile=ci
[prod]
pennsieve_profile_name=prod
[dev]
pennsieve_profile_name=test
[ci]
pennsieve_profile_name=ci
[global] section defines the default profile that is to be used. This basically refers to any section in brackets that stores configuration variables. In this case it refers to 'ci' section.
Within each section, different configuration variables could be defined. In our case, the only variable that needs to be defined is pennsieve_profile_name, which is passed to the Pennsieve2 library.
Module automatic import
Each python file in services/ folder with defined class name that is derived from BaseService is imported as a module to SparcClient class.
For example, Pennsieve module could be used in the following way:
from sparc.client import SparcClient
client = SparcClient(connect=False, config_file='config/config.ini')
# Run module prerequisities, e.g. start Pennsieve agent in the background
!pennsieve agent
# connect to the Pennsieve module, get Pennsieve Agent object
client.pennsieve.connect()
# execute internal functions of the module
client.pennsieve.info()
# alternatively connect all the services available
client.connect() #connect to all services
Test generation - PyTest
Some good resource for implementing tests could be found at Medium.
Documentation - Sphinx tutorial
A fresh start for creating documentation with Sphinx could be found at towardsdatascience. To reproduce steps:
- Create a docs folder
- Run
sphinx-quickstart
in docs folder, fill the required prompts. - Edit
conf.py
andindex.rst
files to adjust them to your needs - Run in docs folder sphinx-apidoc -o . ../src
- Disregard
modules.rst
andsphinx.rst
, attachsphinx.client
to toctree inindex.rst
- Run
make html
in docs folder.
Contribution Guide
- Define configuration variables in config.ini file (e.g api_key, api_secret etc.)
- Create a file in services/
- Create a class within this file that extends BaseService
- The class needs to define all the functions required + may add its own.
Developer Setup
Run pip install -e '.[test]'
to install the dependencies needed for a development environment.
Run pytest --cov=./src
to run the tests and get a test coverage summary.
Run pytest --cov-report html --cov=./src
to run the tests and get a full HTML coverage report output to htmlcov
.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for sparc.client-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d64f2388d395a9e00f554d6ebcf81beb18f74de0894c2d03bc34465bfa01d277 |
|
MD5 | f1ffbf583271c853536b529623e03bf1 |
|
BLAKE2b-256 | c134891595f1ddb50c4ac897a7cb4356ec2f208f7b7efc17277522b368d7bd8a |