Skip to main content

AsyncIO Client for Lancium

Project description

Build Status Verification codecov Documentation Status PyPI version PyPI - Python Version License: MIT Black

aiolancium

aiolancium is a simplistic python REST client for the Lancium Compute REST API utilizing asyncio. The client itself has been developed against the Lancium Compute REST API documentation.

Installation

aiolancium can be installed via PyPi using

pip install aiolancium

How to use aiolancium

from aiolancium.auth import Authenticator
from aiolancium.client import LanciumClient

# Authenticate yourself against the API and refresh your token if necessary
auth = Authenticator(api_key="<your_api_key>")

# Initialise the actual client
client = LanciumClient(api_url="https://portal.lancium.com/api/v1/", auth=auth)

# List details about the `lancium/ubuntu` container
await client.images.list_image("lancium/ubuntu")

# Create your hellow world first job.
job = {"job": {"name": "GridKa Test Job",
                   "qos": "high",
                   "image": "lancium/ubuntu",
                   "command_line": 'echo "Hello World"',
                   "max_run_time": 600}}

await client.jobs.create_job(**job)

# Show all your jobs and their status in Lancium compute
jobs = await client.jobs.show_jobs()

for job in jobs["jobs"]:
    # Retrieve the stdout/stdin output of your finished jobs
    await client.jobs.download_job_output(job["id"], "stdout.txt")
    await client.jobs.download_job_output(job["id"], "stderr.txt")
    
    # or download them to disk
    await client.download_file_helper("stdout.txt", "stdout.txt", job["id"])
    await client.download_file_helper("stderr.txt", "stderr.txt", job["id"])

# Delete all your jobs in Lancium compute
for job in jobs["jobs"]:
    await client.jobs.delete_job(id=job["id"])

In order to simplify file uploads and downloads to/from the Lancium compute platform, an upload/download helper method has been added to the client. The upload helper takes care of reading a file in binary format and uploading it in 32 MB chunks (default) to the Lancium persistent storage. The download helper downloads a file from the Lancium persistent storage to the local disks. The download helper also supports the download of jobs outputs (stdout.txt, stderr.txt) to local disk (see example above). Unfortunately, streaming of data is not support by the underlying simple-rest-client. Thus, the entire file is downloaded to memory before writing to the disk.

from aiolancium.auth import Authenticator
from aiolancium.client import LanciumClient

# Authenticate yourself against the API and refresh your token if necessary
auth = Authenticator(api_key="<your_api_key>")

# Initialise the actual client
client = LanciumClient(api_url="https://portal.lancium.com/api/v1/", auth=auth)

# Upload /bin/bash to /test on the Lancium persistent storage
await client.upload_file_helper(path="test", source="/bin/bash")

# Get information about the uploaded file
await client.data.get_file_info("/test")

# Download the file again
await client.download_file_helper("/test", destination="test_downloaded_again")

# Delete the uploaded file again, the 
arg = {"file-path": "/test"}
await client.data.delete_data_item(**arg)

# Alternative approach to delete the uploaded file
await client.data.delete_data_item("/test")

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

aiolancium-0.2.1.tar.gz (24.7 kB view details)

Uploaded Source

Built Distribution

aiolancium-0.2.1-py3-none-any.whl (25.9 kB view details)

Uploaded Python 3

File details

Details for the file aiolancium-0.2.1.tar.gz.

File metadata

  • Download URL: aiolancium-0.2.1.tar.gz
  • Upload date:
  • Size: 24.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.11.0 Darwin/21.6.0

File hashes

Hashes for aiolancium-0.2.1.tar.gz
Algorithm Hash digest
SHA256 ef930383654a844e8dec71f44a51afe10bc2918e51a724331ef3e59bc76b7a57
MD5 74590fbbc6bc0623d0afef7aad957cb4
BLAKE2b-256 fc0a6be633a467911bfa47bb93678c29f2579ea806751babbaca2076f6616117

See more details on using hashes here.

File details

Details for the file aiolancium-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: aiolancium-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 25.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.11.0 Darwin/21.6.0

File hashes

Hashes for aiolancium-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a14072dfb4c3f0ac94104435fae5bd8005f028eb4ae02d37651649612d262ecd
MD5 60404f70845df1aba81faa4e8110e958
BLAKE2b-256 559092fd933df5e74263cfb56992a8e405e2569046facd516b78949bc15e54e5

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