Skip to main content

Simple wrapper for requests, to ease use of HEPData Converter WebServices API

Project description

GitHub Actions Status Coveralls Status License GitHub Releases PyPI Version GitHub Issues

hepdata-converter-ws-client

Light client wrapper for interaction with hepdata-converter-ws (Web Services). It is recommended to use this wrapper instead of manually creating requests to hepdata-converter-ws.

The reason for creating this package is the fact that the hepdata-converter-ws API requires compressing files into tar.gz format and encoding using Base64 in order to pass them as an argument in the JSON request. Doing this manually every time someone wants to call the hepdata-converter-ws API was a little cumbersome: that's why this light wrapper was born.

Additionally, the library provides additional functionality when it comes to writing the output of the convert function: instead of receiving raw tar.gz content it is possible to extract to a specified file path.

Sample usage

The library exposes one single function hepdata_converter_ws_client.convert which is very similar to hepdata_converter.convert. It accepts the additional argument url, and restricts input / output to str, unicode and file objects (objects supporting read, write, seek, tell).

The options parameter should be the same as with the hepdata_converter library.

The timeout parameter can be used to set a timeout for requests (defaults to 600s).

The library defines the exception hepdata_converter_ws_client.Error which will be thrown on timeouts or other errors connecting to the server.

Function description

hepdata_converter_ws_client.convert function has proper docstring describing its arguments and return values.

Convert using file paths

Arguments passed as input and output can be file paths or file objects. Below is an example of how to utilise the convert function with file paths.

import hepdata_converter_ws_client

# using path to input file, and writing output directly to output_path
input_path = '/path/to/input.txt'
output_path = '/path/to/output/dir'
hepdata_converter_ws_client.convert('http://hepdata-converter-ws-addr:port', input_path, output_path,
                                    options={'input_format': 'oldhepdata'})

Convert using input path and output file object

Input can always be a file object (as long as the input Parser supports single files). Output can be a file object only if the keyword argument extract=False. In this case the binary content of the returned tar.gz file will be written to the output file object. It is then the responsibility of the user to decompress it.

import hepdata_converter_ws_client
from io import BytesIO
# using path to input file, writing to output stream
input_path = '/path/to/input.txt'
output = BytesIO()
hepdata_converter_ws_client.convert('http://hepdata-converter-ws-addr:port', input_path, output,
                                    options={'input_format': 'oldhepdata'}, extract=False)

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

hepdata-converter-ws-client-0.2.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

hepdata_converter_ws_client-0.2.0-py2.py3-none-any.whl (12.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file hepdata-converter-ws-client-0.2.0.tar.gz.

File metadata

  • Download URL: hepdata-converter-ws-client-0.2.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.1

File hashes

Hashes for hepdata-converter-ws-client-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ad5a61fb4c0581dfa04c8445c8d87d58b2c185eacd7741a2ef99d94a40dcc27a
MD5 6354d45501b6fd814ae179feea55bd3b
BLAKE2b-256 ee258cd5d0ee0bc8631b59747d81ab78cd171e65a76068a3d9ccd406607f3758

See more details on using hashes here.

File details

Details for the file hepdata_converter_ws_client-0.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: hepdata_converter_ws_client-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.1

File hashes

Hashes for hepdata_converter_ws_client-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 03ce94dd11b364f47b71fd706dbad003b0b48cacbd02acbff56abb66739b053c
MD5 8d93a1c324b5fd569f02e2dff47093af
BLAKE2b-256 50809cef977bbe228aeeeee416af4b4306bcb0f41207fe00854de43882bf4330

See more details on using hashes here.

Supported by

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