Skip to content

Commit b259e9a

Browse files
committed
Add Connection.webeditor() for link to openEO Web Editor
1 parent d5180c3 commit b259e9a

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- Added `show_error_logs` argument to `cube.execute_batch()`/`job.start_and_wait()`/... to toggle the automatic printing of error logs on failure ([#505](https://github.com/Open-EO/openeo-python-client/issues/505))
13+
- Added `Connection.webeditor()` to build link to the openEO backend in the openEO Web Editor
1314

1415
### Changed
1516

openeo/rest/connection.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import os
1010
import shlex
1111
import sys
12+
import urllib.parse
1213
import warnings
1314
from collections import OrderedDict
1415
from pathlib import Path, PurePosixPath
@@ -1967,6 +1968,18 @@ def version_info(self):
19671968
}),
19681969
}
19691970

1971+
def webeditor(self, *, editor_url: str = "https://editor.openeo.org/", anonymous: bool = False) -> str:
1972+
"""
1973+
Generate URL to open this backend in the openEO Web Editor.
1974+
"""
1975+
# TODO: add option to directly open link with `webbrowser.open()`?
1976+
# TODO: add option to print (or jupyter-aware display) the link instead of returning it?
1977+
params = {"server": self.root_url}
1978+
if anonymous:
1979+
params["discover"] = "1"
1980+
url = f"{editor_url}?{urllib.parse.urlencode(params)}"
1981+
return url
1982+
19701983

19711984
def connect(
19721985
url: Optional[str] = None,

tests/rest/test_connection.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4010,3 +4010,10 @@ def test_create_job_intermediate_resultst(self, con120, dummy_backend):
40104010
"result": True,
40114011
},
40124012
}
4013+
4014+
4015+
def test_webeditor(requests_mock):
4016+
requests_mock.get(API_URL, json=build_capabilities())
4017+
con = Connection(API_URL)
4018+
assert con.webeditor() == "https://editor.openeo.org/?server=https%3A%2F%2Foeo.test%2F"
4019+
assert con.webeditor(anonymous=True) == "https://editor.openeo.org/?server=https%3A%2F%2Foeo.test%2F&discover=1"

0 commit comments

Comments
 (0)