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
0.1.0 - 28.10.2014 - 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 webbrowser.open(AzureOAuth.get_authorization_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 Service Principal access credentials, you can also authenticate with these. You will need to add the crdentials to the batch_apps.ini configuration file:
service_principal = my_service_client_id@my_tenant 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
File details
Details for the file azure-batch-apps-0.1.0.tar.gz
.
File metadata
- Download URL: azure-batch-apps-0.1.0.tar.gz
- Upload date:
- Size: 301.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e587b69a81709d712084fc70734ec5a395cf506ab198a0fde1ff65184e965982 |
|
MD5 | da04a19a8e1557070ea65eb35256b0ea |
|
BLAKE2b-256 | f03ac223a82e5d6de7f35d50385819fcefd555affeb29fcd4ec3387a0f0f266c |