OBiBa/Opal python client.
Project description
Opal Python ![Build Status](https://pypi-camo.freetls.fastly.net/f615bff4fa32484b4439686c34d05eb21ca58c29/68747470733a2f2f6170702e7472617669732d63692e636f6d2f6f626962612f6f70616c2d707974686f6e2d636c69656e742e7376673f6272616e63683d6d6173746572)
This Python-based command line tool allows to access to a Opal server through its REST API. This is the perfect tool for automating tasks in Opal using shell scripts.
See also the Opal R Client which offers a comprehensive programming interface.
- Read the documentation.
- Have a bug or a question? Please create an issue on GitHub.
- Continuous integration is on Travis.
Usage
Install with:
pip install obiba-opal
Note: obiba-opal
depends on pycurl
which itself depends on system libraries (mostly OpenSSL related). In case pycurl
installation
fails with pip, a quick fix is to install it via a system package:
# on Debian systems
sudo apt-get install python3-pycurl
# on RPM systems
sudo yum install python3-pycurl
CLI
To get the options of the command line:
opal --help
This command will display which sub-commands are available. For each sub-command you can get the help message as well:
opal <subcommand> --help
The objective of having sub-command is to hide the complexity of applying some use cases to the Opal REST API. More sub-commands will be developed in the future.
API
Opal Python client can be easily extended by using the exposed classes. The classes *Command
return an Opal task object, to be followed with the TaskService
. The classes *Service
perform immediate operations.
from obiba_opal import OpalClient, HTTPError, Formatter, ImportCSVCommand, TaskService, FileService, DictionaryService
# if 2-factor auth is enabled, user will be asked for the secret code
# Personal access token authentication is also supported (and recommended)
client = OpalClient.buildWithAuthentication(server='https://opal-demo.obiba.org', user='administrator', password='password')
try:
# upload a local CSV data file into Opal file system
fs = FileService(client)
fs.upload_file('./data.csv', '/tmp')
# import this CSV file into a project
task = ImportCSVCommand(client).import_data('/tmp/data.csv', 'CNSIM')
status = TaskService(client).wait_task(task['id'])
# clean data file from Opal
fs.delete_file('/tmp/data.csv')
if status == 'SUCCEEDED':
dico = DictionaryService(client)
table = dico.get_table('CNSIM', 'data')
# do something ...
dico.delete_tables('CNSIM', ['data'])
else:
print('Import failed!')
# do something ...
except HTTPError as e:
Formatter.print_json(e.error, True)
finally:
client.close()
Mailing list
Have a question? Ask on our mailing list!
http://groups.google.com/group/obiba-users
License
OBiBa software are open source and made available under the GPL3 licence. OBiBa software are free of charge.
OBiBa acknowledgments
If you are using OBiBa software, please cite our work in your code, websites, publications or reports.
"The work presented herein was made possible using the OBiBa suite (www.obiba.org), a software suite developed by Maelstrom Research (www.maelstrom-research.org)"
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
Built Distribution
Hashes for obiba_opal-5.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51d27c35bbf147289dffe62fc561ef5e7a01afd118fdf9f5941c4483f0d08061 |
|
MD5 | 0a243388c80f5f0079e7f5eb41a81030 |
|
BLAKE2b-256 | 4d47aa3624f033a50c33e7133e4b8fd8ac47cd1349d57cd63a61c6e61d85f22a |