Skip to main content

MIKE Cloud Platform SDK for Python

Project description

DHI

MIKE Cloud Platform SDK for Python

What is MIKE Cloud Platform SDK for Python?

MIKE Cloud Platform SDK for Python allows you to programmatically access MIKE Cloud Platform from Python. It also includes set of CLI tools to manipulate data and access services in MIKE Cloud Platform.

Here is a small example:

plt cfg login --login
plt prj create --name "My project"
plt prj ls

See the documentation for more examples.

MIKE Cloud Platform SDK for Python is in development; some features are missing and there could be even bugs :-o

Requirements

You need Python 3.8 or later. In Ubuntu, Mint and Debian you can install Python 3 like this:

$ sudo apt-get install python3 python3-pip python3-wheel python3-cffi python3-cryptography python3-greenlet python3-gevent python3-yaml

In Alpine:

$ apk add --no-cache bash python3 py3-pip py3-wheel py3-cffi py3-cryptography py3-greenlet py3-gevent py3-yaml

For other Linux flavors, macOS and Windows, packages are available at

https://www.python.org/getit/

Quick start

MIKE Cloud Platform SDK for Python and additional packages are installed using pip:

$ pip install -U dhi-platform

If you want to run the latest stable version of the code, you can install from git:

$ pip install -U azure-identity azure-storage-blob signalrcore signalr-async PyYAML
$ pip install -U git+https://dhigroup@dev.azure.com/dhigroup/MIKE/_git/mike-platform-sdk-py@master

Or if you want to run the latest development (unstable) version of the code from git:

$ pip install -U azure-identity azure-storage-blob signalrcore signalr-async PyYAML
$ pip install -U git+https://dhigroup@dev.azure.com/dhigroup/MIKE/_git/mike-platform-sdk-py@develop

Manual installation: get files from mike-platform-sdk-py repository (https://dhigroup@dev.azure.com/dhigroup/MIKE/_git/mike-platform-sdk-py). Add "src" directory to PYTHONPATH and "bin" directory to PATH. Install additional packages: azure-identity, azure-storage-blob, signalrcore, signalr-async and PyYAML:

$ pip install -U azure-identity azure-storage-blob signalrcore signalr-async PyYAML

How to authenticate in Python

When creating MIKE Cloud Platform clients in Python, you must provide credentials. There are three ways to do that:

  1. Device code flow

This is the recommended way to authenticate when using the Python SDK. You need to register your device with the Platform IAM system (contact wdpservice@dhigroup.com) Note that with device code flow, all requests will be performed on behalf of the device, not on behald of the user who set the device up.

Example:

from dhi.platform.authentication import DeviceCodeDhiIdentity
from dhi.platform.metadata import MetadataClient

client_id = "<my client id>"
client_secret = "<my client secret>
identity = DeviceCodeDhiIdentity(client_id, client_secret environment="dev", forcelogin=True)
metadata_client = MetadataClient(identity=identity)
  1. Using open api key

We recommend using the device code flow option above. However, open api key is still an available option. When using api, all requests will be performed on behalf of the creator of the open api account.

Provided you have a valid api key and the corresponding open api key account has been assigned to a project, you can create an identity and provide that to clients. Open API key for the MIKE Cloud Platform can be requested through your DHI Cloud Platform Account Administrator (i.e. for DHI through mike@dhigroup.com) and assigned to projects using Data Admin UI application.

Example:

from dhi.platform.authentication import ApiKeyIdentity
from dhi.platform.metadata import MetadataClient
customer_id = "<customer id>"
key = "<api key uuid>"
identity = ApiKeyIdentity(customer_id=customer_id, apikey=key)
client = MetadataClient(identity=identity)
  1. Using interactive user login

When using interactive user login, all requests would be performed on behalf of the logged in user This option is not implement out of the box. It requires a server component running on the client side. The server component must be able to handle authentication callback HTTP request from the the DHI MIKE Cloud Platform IAM. This option would be suitable for example when using this python package from a Python web application backed. Contact wdpservice@dhigroup.com if you need more information.

If you want to target a different environment than production, provide the optional environment parameter.

Web site and documentation

Documentation and additional information is available at the web site:

https://develop.mike-cloud.com

Or you can jump straight to the documentation:

https://develop.mike-cloud.com/docs/

Troubleshooting

Depending on your configuration, you may have to run pip like this:

$ pip install --no-deps -U dhi-platform

This doesn't automatically install the appropriate version of azure-identity, azure-storage-blob, signalrcore, signalr-async and PyYAML. You can install them manually:

$ pip install -U azure-identity azure-storage-blob signalrcore signalr-async PyYAML

If the plt command isn't found after installation: After pip install, the plt script and dependencies, will be installed to system-dependent locations. Sometimes the script directory will not be in PATH, and you have to add the target directory to PATH manually or create a symbolic link to the script. In particular, on macOS, the script may be installed under /Library/Frameworks:

/Library/Frameworks/Python.framework/Versions/<version>/bin

In Windows, the script is generally installed in \PythonNN\Scripts. So, type check a program like this (replace \Python38 with your Python installation path):

C:\>\Python38\python \Python38\Scripts\plt ...

Working with virtualenv

If you are using virtualenv, make sure you are running a python3 environment. Installing via pip3 in a v2 environment will not configure the environment to run installed modules from the command line.

$ pip install -U virtualenv
$ python3 -m virtualenv env

Development status

MIKE Cloud Platform SDK for Python is beta software.

Changelog

Issue tracker

License

MIKE Cloud Platform SDK for Python is licensed under the terms of the MIT License (see the file LICENSE).

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

dhi_platform-1.1.0.tar.gz (262.5 kB view details)

Uploaded Source

Built Distribution

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

dhi_platform-1.1.0-py3-none-any.whl (343.2 kB view details)

Uploaded Python 3

File details

Details for the file dhi_platform-1.1.0.tar.gz.

File metadata

  • Download URL: dhi_platform-1.1.0.tar.gz
  • Upload date:
  • Size: 262.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.18

File hashes

Hashes for dhi_platform-1.1.0.tar.gz
Algorithm Hash digest
SHA256 9b86a7fc47b6ec9bb833398d15391268846cec73e0d7f8c3da1ef2c6d4e05db0
MD5 335245a7b4b90c902cb438a2652d8a6f
BLAKE2b-256 a6add62e5c886dd7a4560b318f35dc6f778edd2c8137eee3442c88a74c741eb7

See more details on using hashes here.

File details

Details for the file dhi_platform-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: dhi_platform-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 343.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.18

File hashes

Hashes for dhi_platform-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0459d899bd7770933006ebbac55b08ea54297e4fdd562990acd098b9b58cc557
MD5 ebd7957f119afc2ceeff128f7a18a524
BLAKE2b-256 8121762d127a0723d71c728fb3524bfe2cd2ceb059a7a9bcb6d7d83518573bb8

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