Skip to main content

morpheus-data-client

Python client to Morpheus Data API

https://apidocs.morpheusdata.com/

Tests Codecov

Usage

import os
from morpheus_data_api import MorpheusDataApi

os.environ['MORPHEUS_HOST'] = 'somehost.com'
os.environ['MORPHEUS_TOKEN'] = 'foobar'

api = MorpheusDataApi()
type_data = {
    'optionType': {
        'name': 'foo',
        'type': 'text',
        'description': 'foo',
        'fieldLabel': 'foo',
        'fieldName': 'foo'
    }
}

def type_names():
    r = api.call(
        'library/option-types', transform='optionTypes[].name'
    )
    return r

assert 'foo' not in type_names()

api.upsert('library/option-types', 'foo', type_data)
assert 'foo' in type_names()

type_data['optionType']['description'] = 'FOO'
assert api.get('library/option-types', 'foo')['description'] == 'foo'

api.upsert('library/option-types', 'foo', type_data)
assert api.get('library/option-types', 'foo')['description'] == 'FOO'

api.delete('library/option-types', 'foo')
assert 'foo' not in type_names()

Deploy/Undeploy Config

Given a yaml config file tests/data/option_types/foo1.yaml:

$optionType:
  name: foo1
  fieldName: foo1
  type: select
  description: foo1
  fieldLabel: foo1
  optionList:
    id:
      $optionTypeList:
        name: foo1
        type: manual
        initialDataset:
          $dataset:
            - bar
            - baz

It can be deployed/undeployed like so:

import os
from morpheus_data_api import MorpheusDataApi

os.environ['MORPHEUS_HOST'] = 'somehost.com'
os.environ['MORPHEUS_TOKEN'] = 'foobar'

api = MorpheusDataApi()
api.deploy_files('option_types/foo1.yaml')
api.deploy_files('option_types/foo1.yaml', undeploy=True)

Or deployed through the morpheus-data-api console script

$ morpheus-data-api deploy tests/data/option_types/foo1.yaml
created optionTypeList foo1 [14]
created optionType foo1 [1766]
1/1] deployed foo1.yaml
deployed 1/1 file(s)

Then undeployed:

$ morpheus-data-api undeploy tests/data/option_types/foo1.yaml
deleted optionType foo1 [1766]
deleted optionTypeList foo1 [14]
1/1] undeployed foo1.yaml
undeployed 1/1 file(s)

This works by upserting or deleting nested entities in the expected order, and linking referential IDs to the parent object

See tests/data/catalog_items/item1.yaml for larger example

$ morpheus-data-api deploy tests/data/catalog_items/item1.yaml
created task task1 [9]
created optionType item1 [1767]
created optionTypeList item2 [15]
created optionType item2 [1768]
created taskSet item1 [5]
created catalogItemType item1 [3]
created schedule schedule1 [6]
created job job1 [11]
1/1] deployed item1.yaml
deployed 1/1 file(s)

Variables

The following variables are supported within the config file

variable description example
$createPath nested below an $api object, override the path used to create entity $createPath: /api/library/instance-types/${id:instanceTypes:blueprint1.instanceType1}/layouts
$dataset convert list of values to json optionType dataset $dataset: ['foo', 'bar']
$datasetCsv convert contents of local csv file to json optionType dataset $datasetCsv: data.csv
$deleteIds delete additional entities during undeploy $deleteIds: [${id:optionTypes:foo}]
$deletePath nested below an $api object, override the path used to delete entity $deletePath: /api/library/instance-types/${id:instanceTypes:blueprint1.instanceType1}/layouts
$entity nested below an $api object, override entity name $entity: instanceTypeLayout
$entityId nested below an $api object, override entity ID $entityId: key/128/foobar
$fileContent read contents of local file $fileContent: foo.py
$id lookup entity ID from ${id:path:name} expression id: ${id:optionTypes:foo}
$json convert value to JSON $json: [1,2,3]
$setName nested below an $api object, don't automatically set entity name if false $setName: false
$updatePath nested below an $api object, override the path used to update entity $updatePath: /api/library/instance-types/${id:instanceTypes:blueprint1.instanceType1}/layouts
$validate nested below an $api object, disable validation if false $validate: false

Console Script

The morpheus-data-api console script is installed as part of setup.py

usage: morpheus-data-api [-h] [--name NAME] [-q Q] [-y]
                         {deploy,undeploy,get,export} path

Query Morpheus data API and deploy config to it

positional arguments:
  {deploy,undeploy,get,export}
  path                  yaml file, dir of yaml files or api path

optional arguments:
  -h, --help            show this help message and exit
  --name NAME           export name
  -q Q                  jmespath query
  -y                    output in yaml format

MockMorpheusDataApi

Bundled into the package is mock.MockMorpheusDataApi() which provides full persistent mocking of Morpheus API. See tests/test_morpheus_data_api.py for examples how this is used.

License

The license is Apache 2.0, see LICENSE for the details.

Metadata

Release files for morpheus-data-api 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for morpheus-data-api 0.0.2
File Interpreter ABI Platform
morpheus_data_api-0.0.2-py2.py3-none-any.whl Python 2, Python 3 none any Details

Release files / morpheus_data_api-0.0.2-py2.py3-none-any.whl

Download URL morpheus_data_api-0.0.2-py2.py3-none-any.whl
Size 18.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
4210593fe8c3b8a8019c8f960006840c4dca0f9c92087ecadd8703d514647c17
BLAKE2b-256 checksum
How to use checksums
618cb3a7b534c9b9df1c7cbcb929a9e9c7ba73b195eb0368ed122a7da00dcfb8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.2.0 pkginfo/1.7.1 requests/2.21.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.6.8

Security for morpheus-data-api 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.2 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page