Skip to content

Commit bcb9f3a

Browse files
authored
Merge pull request #61 from equinor/thin-client
new thin client + tests
2 parents 0751b3b + 85a204a commit bcb9f3a

5 files changed

Lines changed: 603 additions & 3 deletions

File tree

README.md

Lines changed: 203 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,210 @@
11
# sumo-wrapper-python
22
Python wrappers for Sumo APIs
33

4-
## Install by running:
4+
## Install:
55

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

88
For internal Equinor users, this package is available through the Komodo distribution.
9+
10+
# Table of contents
11+
12+
- [CallSumoApi](#callsumoapi)
13+
- [Initialization](#initialization)
14+
- [Parameters](#parameters)
15+
- [Examples](#examples)
16+
- [search()](#search)
17+
- [searchroot()](#searchroot)
18+
- [SumoClient](#SumoClient)
19+
- [Initialization](#initialization)
20+
- [Parameters](#parameters)
21+
- [Methods](#methods)
22+
- [get(path, **params)](#getpath-params)
23+
- [post(path, json, blob)](#postpath-json-blob)
24+
- [put(path, json, blob)](#putpath-json-blob)
25+
- [delete(path)](#deletepath)
26+
27+
# CallSumoApi
28+
Predefined methods for various sumo operations. I.e uploading, searching for and deleting metadata and blobs.
29+
30+
### Initialization
31+
```python
32+
from sumo.wrapper import CallSumoApi
33+
34+
sumo = CallSumoApi()
35+
```
36+
37+
### Parameters
38+
```python
39+
class CallSumoApi:
40+
def __init__(
41+
self,
42+
env="dev",
43+
resource_id=None,
44+
client_id=None,
45+
outside_token=False,
46+
writeback=False,
47+
):
48+
```
49+
50+
## Examples
51+
All `CallSumoApi` methods accept a `bearer` argument which lets the user use an existing access token instead of generating a new one.
52+
53+
### search()
54+
Search all objects in sumo.
55+
56+
#### Parameters
57+
```python
58+
def search(
59+
self,
60+
query,
61+
select=None,
62+
buckets=None,
63+
search_from=0,
64+
search_size="100",
65+
search_after=None,
66+
bearer=None,
67+
):
68+
```
69+
70+
#### Usage
71+
```python
72+
# Find objects where class = surface
73+
search_results = sumo.search(query="class:surface", search_size="10")
74+
75+
# Get child objects for a specific object
76+
parent_id = "1234"
77+
children = sumo.search(query=f"_sumo.parent_object:{parent_id}")
78+
79+
# Get buckets for child object classes (i.e surface, table, polygon)
80+
# This will return a count for every class value
81+
buckets = sumo.search(
82+
query=f"_sumo.parent_object:{parent_id}",
83+
buckets=["class.keyword"]
84+
)
85+
```
86+
87+
### searchroot()
88+
Search for parent objects (object without parent)
89+
90+
#### Parameters
91+
```python
92+
def searchroot(
93+
self,
94+
query,
95+
select=None,
96+
buckets=None,
97+
search_from=0,
98+
search_size="100",
99+
bearer=None,
100+
):
101+
```
102+
103+
#### Usage
104+
```python
105+
# Get 3 top level objects for a specific user
106+
peesv_objects = sumo.searchroot(
107+
query="fmu.case.user.id:peesv",
108+
search_size=3
109+
)
110+
```
111+
112+
# SumoClient
113+
An ultra thin wrapper class.
114+
115+
### Initialization
116+
117+
```python
118+
from sumo.wrapper import SumoClient
119+
120+
sumo = SumoClient(env="dev")
121+
```
122+
123+
### Parameters
124+
125+
```python
126+
class SumoClient:
127+
def __init__(
128+
self,
129+
env,
130+
access_token=None,
131+
logging_level='INFO',
132+
write_back=False
133+
):
134+
```
135+
- `env*` (string) - sumo environment
136+
137+
- `logging_level` (string) - logging level: "INFO", "DEBUG", "WARNING", "ERROR"
138+
139+
- `access_token` (string) - bearer token for authentication
140+
141+
- `write_back` (boolean) - update token cache
142+
143+
If no `access_token` is provided, an authentication code flow is triggered to retrieve a token.
144+
145+
## Methods
146+
`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.
147+
148+
149+
All methods accepts a path argument. Path parameters can be interpolated into the path string. Example:
150+
```python
151+
object_id = "1234"
152+
153+
# GET/objects('{obejctid}')
154+
sumo.get(f"/objects('{object_id}')")
155+
```
156+
157+
### get(path, **params)
158+
Performs a GET-request to sumo-core. Accepts query parameters as keyword arguments.
159+
160+
```python
161+
# Retrieve userdata
162+
user_data = sumo.get("/userdata")
163+
164+
# Search for objects
165+
results = sumo.get("/search",
166+
query="class:surface",
167+
size:3,
168+
select=["_id"]
169+
)
170+
171+
# Get object by id
172+
object_id = "159405ba-0046-b321-55ce-542f383ba5c7"
173+
174+
obj = sumo.get(f"/objects('{object_id}')")
175+
```
176+
177+
178+
### post(path, json, blob)
179+
Performs a POST-request to sumo-core. Accepts json and blob, but not both at the same time.
180+
```python
181+
# Upload new parent object
182+
parent_object = sumo.post("/objects", json=parent_meta_data)
183+
184+
# Upload child object
185+
parent_id = parent_object["_id"]
186+
187+
child_object = sumo.post(f"/objects('{parent_id}')", json=child_meta_data)
188+
```
189+
190+
### put(path, json, blob)
191+
Performs a PUT-request to sumo-core. Accepts json and blob, but not both at the same time.
192+
```python
193+
# Upload blob to child object
194+
child_id = child_object["_id"]
195+
196+
sumo.put(f"/objects('{child_id}')/blob", blob=blob)
197+
```
198+
199+
### delete(path)
200+
Performs a DELETE-request to sumo-core.
201+
```python
202+
# Delete blob
203+
sumo.delete(f"/objects('{child_id}')/blob")
204+
205+
# Delete child object
206+
sumo.delete(f"/objects('{child_id}')")
207+
208+
# Delete parent object
209+
sumo.delete(f"/objects('{parent_id}')")
210+
```

src/sumo/wrapper/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
from ._call_sumo_api import CallSumoApi
1+
from ._call_sumo_api import CallSumoApi
2+
from ._sumo_client import SumoClient

0 commit comments

Comments
 (0)