Skip to main content

Batch Apps Python Client

Project description

The package is to enable Azure Batch Apps customers to interact with the Management API using Python.

License

This project is licensed under the MIT License. For details see LICENSE.txt or visit http://opensource.org/licenses/MIT

Installation

This package has been tested with Python 2.6, 2.7, 3.2, 3.3 and 3.4

>> pip install azure-batch-apps

Required packages:

Documentation

The documentation is generated by Sphinx and can be found zipped up in the project root. It is also hosted online here.

Release History

  • 2014-11-03 - 0.1.1 - Authentication bug fixes

  • 2014-10-28 - 0.1.0 - Beta Release

Usage

Authentication

The module authenticates with Azure Active Directory (an implementation of OAuth2). The batchapps module provides a helper class to assist in retrieving an AAD token using Requests-OAuthlib. However if you have a preferred OAuth implementation, you can authenticate with this instead:

from batchapps import AzureOAuth
import webbrowser

auth_url, state = AzureOAuth.get_authorization_url()
webbrowser.open(auth_url)
redirect_url = input("Please paste the redirect url here: ")

creds = AzureOAuth.get_authorization_token(redirect_url)

Or alternatively, if you use a different AAD implementation:

from batchapps import Credentials
import my_oauth

aad_token = my_oauth.get_token()
creds = Credentials(aad_token)

If you have Unattended Account credentials, you can also authenticate with these. You will need to add the crdentials to the batch_apps.ini configuration file:

service_principal = ClientId=abc;TenantId=abc
service_principal_key = my_service_password

Then you can authenticate with these credentials:

from batchapps import AzureOAuth

creds = AzureOAuth.get_principal_token()

Once you have logged in for the first time, your session will be auto-refreshed for a limited time, so you will not need to re-authenticate. If you have a stored session, you can authenticate with:

from batchapps import AzureOAuth

creds = AzureOAuth.get_session()

Job Management

Job management, including submission, monitoring, and accessing outputs is done through the JobManager class:

from batchapps import AzureOAuth, JobManager

creds = AzureOAuth.get_session()
mgr = JobManager(creds)

my_job = mgr.create_job("First Job")

# Apply any custom parameters and source files here
job_id = my_job.submit()['jobid']

job_progress = mgr.get_job(jobid=job_id)

if job_progress.status == 'Complete':
        job_progress.get_output('c:\\my_download_dir')

else:
        job_progress.cancel()

File Management

File management, including syncing job source files and dependencies to the cloud can be done using the FileManager class:

from batchapps import AzureOAuth, FileManager

creds = AzureOAuth.get_session()
mgr = FileManager(creds)

job_source = mgr.create_file('C:\\start_job.bat')
file_collection = mgr.files_from_dir('c:\\my_job_assets')
file_collection.add(job_source)

file_collection.upload()

# Check files previously uploaded matching a certain name
mgr.find_files('start_job.bat')

# Retrieve a list of all uploaded files
mgr.list_files()

Application Configuration

To set up a new application type, and any custom parameters you want associated with it, it can be added to the configuration file. You can edit the file directly, or via the Configuration class. By default the configuration file will be created in the user directory:

from batchapps import Configuration

cfg = Configuration(log_level='debug', default=True)
cfg.add_application('my_app', 'my.endpoint.com', 'client_id')

# Set this application as the current job type
cfg.application('my_app')

# Set this as the default application for all future jobs
cfg.set_default_application()

# Add some custom parameters
cfg.set('start_val') = 1
cfg.set('end_val') = 100
cfg.set('timeout') = 500

# Save additional parameters to file
cfg.save_config()

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

azure-batch-apps-0.1.1.tar.gz (301.5 kB view details)

Uploaded Source

File details

Details for the file azure-batch-apps-0.1.1.tar.gz.

File metadata

File hashes

Hashes for azure-batch-apps-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c9b0b5faabff1e3dd49aaacb54ef3c97c5f0991b34c7a59743c0283255a5b80f
MD5 256f494f2db5237beb777817dac99abb
BLAKE2b-256 0ba0dd19d2f2a5d314321417ebdcb31724ee1c0a7093239554b3866f8f603798

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