Skip to main content

A Python 3 client for AzureMl web services

Project description

An *unofficial* generic client stack for azureML web services, working with python 3.

As opposed to the ‘complete’ AzureML client library, this library is much simpler and is only focused on calling the deployed web services using python 3. It does not require your AzureML workspace id and API key, only the deployed services’ URL and API key.

You may use it for example * to show to your customers how to consume your AzureML cloud services. * to make simple ‘edge’ devices consume your AzureML cloud services (if they support python :) ).

Main features

  • Creates the Web Services requests from dataframe inputs and dataframe/dictionary parameters, and maps the responses to dataframes too

  • Maps the errors to more friendly python exceptions

  • Supports both Request/Response and Batch mode

  • In Batch mode, performs all the Blob storage and retrieval for you.

  • Properly handles file encoding in both modes (utf-8 is used by default as the pivot encoding)

  • Supports global requests.Session configuration to configure the HTTP clients behaviour (including the underlying blob storage client).

Installation

Installation steps

This package is available on PyPI. You may therefore use pip to install from a release

> pip install azmlclient

*Note for conda users*: The only drawback of the method above using pip, is that all dependencies (numpy, pandas, azure-storage) are automatically installed using pip too, and therefore are not downloaded from validated conda repositories. If you prefer to install them from conda, the workaround is to run the following command before installing:

> conda install numpy, pandas, azure-storage==0.33.0

Uninstalling

As usual :

> pip uninstall azmlclient

Examples

First import the package

import azmlclient as ac

Then create variables holding the access information provided by AzureML

base_url = 'https://europewest.services.azureml.net/workspaces/<workspaceId>/services/<serviceId>'
api_key = '<apiKey>'
use_new_ws = False

Then create * the inputs - a dictionary containing all you inputs as dataframe objects

```python
inputs = {"trainDataset": trainingDataDf, "input2": input2Df}
```
  • the parameters - a dictionary

    params = {"param1": "val1", "param2": "val2"}
  • and optionally provide a list of expected output names

    outputNames = ["my_out1","my_out2"]

Finally call in Request-Response mode:

outputs = ac.execute_rr(api_key, base_url, inputs=inputs, params=params, output_names=output_names)

Or in Batch mode. In this case you also need to configure the Blob storage to be used:

# Define the blob storage to use for storing inputs and outputs
blob_account = '<account_id>'
blob_apikey = '<api_key>'
blob_container = '<container>'
blob_path_prefix = '<path_prefix>'

# Perform the call (polling is done every 5s until job end)
outputs = ac.execute_bes(api_key, base_url,
                          blob_storage_account, blob_storage_apikey, blob_container_for_ios,
                          blob_path_prefix=blob_path_prefix,
                          inputs=inputs, params=params, output_names=output_names)

Debug and proxies

Users may wish to create a requests session object using the helper method provided, in order to override environment variable settings for HTTP requests. For example to use Fiddler as a proxy to debug the web service calls:

session = ac.create_session_for_proxy(http_proxyhost='localhost', http_proxyport=8888,
                                      use_http_for_https_proxy=True, ssl_verify=False)

Then you may use that object in the requests_session parameter of the methods:

outputsRR = ac.execute_rr(..., requests_session=session)
outputsB = ac.execute_bes(..., requests_session=session)

Note that the session object will be passed to the underlying azure blob storage client to ensure consistency.

Advanced usage

Advanced users may directly create Batch_Client or RR_Client classes to better control what’s happening.

An optional parameter allow to work with the ‘new web services’ mode (use_new_ws = True - still evolving on MS side, so will need to be updated).

Developers

Packaging

This project uses setuptools_scm to synchronise the version number. Therefore the following command should be used for development snapshots as well as official releases:

python setup.py egg_info bdist_wheel rotate -m.whl -k3

Releasing memo

twine upload dist/* -r pypitest
twine upload dist/*

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

azmlclient-1.0.1-py3-none-any.whl (29.7 kB view details)

Uploaded Python 3

File details

Details for the file azmlclient-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for azmlclient-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c28a5b1448069315fe19446db81bccf56e66d6ea7e9188f6aaece67d577fe4ad
MD5 b0e4443ad84bdfdccd4ad781735992d8
BLAKE2b-256 09b5a5173aa529e37f706f0c6d1061939cb4ac5eda1f1c046e9af31a4e211a12

See more details on using hashes here.

Supported by

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