Skip to main content

Python wrapper for the Sumo API

Project description

sumo-wrapper-python

Python wrappers for Sumo APIs

Install:

pip install git+ssh://git@github.com/equinor/sumo-wrapper-python.git@main

For internal Equinor users, this package is available through the Komodo distribution.

:warning: CallSumoApi is deprecated.

Table of contents

SumoClient

A thin wrapper class for the Sumo API.

Initialization

from sumo.wrapper import SumoClient

sumo = SumoClient(env="dev")

Parameters

class SumoClient:
    def __init__(
        self,
        env:str,
        token:str=None,
        interactive:bool=False,
        verbosity:str="CRITICAL"
    ):
  • env: sumo environment
  • token: bearer token or refresh token
  • interactive: use interactive flow when authenticating
  • verbosity: "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"
token logic

If an access token is provided in the token parameter, it will be used as long as it's valid. An error will be raised when it expires.

If we are unable to decode the provided token as a JWT, we treat it as a refresh token and attempt to use it to retrieve an access token.

If no token is provided, an authentication code flow/interactive flow is triggered to retrieve a token.

Methods

SumoClient has one method for each HTTP-method that is used in the sumo-core API. See examples of how to use these methods below.

All methods accepts a path argument. Path parameters can be interpolated into the path string. Example:

object_id = "1234"

# GET/objects('{obejctid}')
sumo.get(f"/objects('{object_id}')")

get(path, **params)

Performs a GET-request to sumo-core. Accepts query parameters as keyword arguments.

# Retrieve userdata
user_data = sumo.get("/userdata")

# Search for objects
results = sumo.get("/search",
    query="class:surface",
    size:3,
    select=["_id"]
)

# Get object by id
object_id = "159405ba-0046-b321-55ce-542f383ba5c7"

obj = sumo.get(f"/objects('{object_id}')")

post(path, json, blob)

Performs a POST-request to sumo-core. Accepts json and blob, but not both at the same time.

# Upload new parent object
parent_object = sumo.post("/objects", json=parent_meta_data)

# Upload child object
parent_id = parent_object["_id"]

child_object = sumo.post(f"/objects('{parent_id}')", json=child_meta_data)

put(path, json, blob)

Performs a PUT-request to sumo-core. Accepts json and blob, but not both at the same time.

# Upload blob to child object
child_id = child_object["_id"]

sumo.put(f"/objects('{child_id}')/blob", blob=blob)

delete(path)

Performs a DELETE-request to sumo-core.

# Delete blob
sumo.delete(f"/objects('{child_id}')/blob")

# Delete child object
sumo.delete(f"/objects('{child_id}')")

# Delete parent object
sumo.delete(f"/objects('{parent_id}')")

CallSumoApi (deprecated)

Predefined methods for various sumo operations. I.e uploading, searching for and deleting metadata and blobs.

Initialization

from sumo.wrapper import CallSumoApi

sumo = CallSumoApi()

Parameters

class CallSumoApi:
    def __init__(
        self,
        env="dev",
        resource_id=None,
        client_id=None,
        outside_token=False,
        writeback=False,
    ):

Examples

All CallSumoApi methods accept a bearer argument which lets the user use an existing access token instead of generating a new one.

search()

Search all objects in sumo.

Parameters

def search(
    self,
    query,
    select=None,
    buckets=None,
    search_from=0,
    search_size="100",
    search_after=None,
    bearer=None,
):

Usage

# Find objects where class = surface
search_results = sumo.search(query="class:surface", search_size="10")

# Get child objects for a specific object
parent_id = "1234"
children = sumo.search(query=f"_sumo.parent_object:{parent_id}")

# Get buckets for child object classes (i.e surface, table, polygon)
# This will return a count for every class value
buckets = sumo.search(
    query=f"_sumo.parent_object:{parent_id}",
    buckets=["class.keyword"]
)

searchroot()

Search for parent objects (object without parent)

Parameters

def searchroot(
    self,
    query,
    select=None,
    buckets=None,
    search_from=0,
    search_size="100",
    bearer=None,
):

Usage

# Get 3 top level objects for a specific user
peesv_objects = sumo.searchroot(
    query="fmu.case.user.id:peesv",
    search_size=3
)

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

sumo-wrapper-python-0.3.5.tar.gz (31.1 kB view details)

Uploaded Source

Built Distribution

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

sumo_wrapper_python-0.3.5-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

File details

Details for the file sumo-wrapper-python-0.3.5.tar.gz.

File metadata

  • Download URL: sumo-wrapper-python-0.3.5.tar.gz
  • Upload date:
  • Size: 31.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for sumo-wrapper-python-0.3.5.tar.gz
Algorithm Hash digest
SHA256 057bf096c382760605ac3e4259b93c00fc771e9e0be8c926d782ce5e03c9c2f5
MD5 b011381b93c21d8b0ac0f59e079cc370
BLAKE2b-256 9a2ab34f1cd5927c52ec0f3337cc2dbd13ac8d2ac2bc88a0e3c9a5ba6fb9ae0f

See more details on using hashes here.

File details

Details for the file sumo_wrapper_python-0.3.5-py3-none-any.whl.

File metadata

File hashes

Hashes for sumo_wrapper_python-0.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 53bbd6eebf05e10dc7d0215d2c3a8facb232f69277effbf0b42409915d134c7b
MD5 ff2c7e5123673d27685000142ea96efc
BLAKE2b-256 dbcbfb3c04b18d64fc0408d2adab4daa9331f92c685015fab4f4ee07a4ce2c71

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