Python wrapper for the Sumo API
Project description
sumo-wrapper-python
Python wrappers for Sumo APIs
Want to contribute? Read our contributing guidelines
Install:
pip install sumo-wrapper-python
For internal Equinor users, this package is available through the Komodo distribution.
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 environmenttoken
: bearer token or refresh tokeninteractive
: use interactive flow when authenticatingverbosity
: "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, params)
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}')")
Async methods
SumoClient
also has async alternatives get_async
, post_async
, put_async
and delete_async
.
These accept the same parameters as their synchronous counterparts, but have to be awaited.
# Retrieve userdata
user_data = await sumo.get_async("/userdata")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for sumo-wrapper-python-1.0.7.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c1e0a3fd3d458a23c4303cfa42f3b94dddf4c3d1f55dff1a7a0c621286d3e23 |
|
MD5 | 4b9aa10eed797c7a827dc119508507f7 |
|
BLAKE2b-256 | 67a0ac812e9add5ef8fe027412c38b9376330522e1a4837d856e7e9e23cc889a |
Hashes for sumo_wrapper_python-1.0.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b2549b4d559e3a47b341eb7612b7b74802c4c4e89ba95bb9996bd31210d4ac6 |
|
MD5 | 7d4427f47556b3d246e0efc837e02438 |
|
BLAKE2b-256 | f4b9f3ce0c71c8162b4285feec2cfbe146a6770e2541c7f02befdcf81be49be2 |