<jupyter_start><jupyter_text>Using Twitcher Client<jupyter_code># disable ssl warnings
import urllib3
urllib3.disable_warnings()
from twitcher.client import TwitcherService
base_url = 'http://localhost:8000'
twitcher = TwitcherService(base_url, username='demo', password='<PASSWORD>', verify=False)<jupyter_output><empty_output><jupyter_text>Register Client APP<jupyter_code>client = twitcher.add_client_app(name='test1', redirect_uri='http://demo/test1')
client<jupyter_output><empty_output><jupyter_text>Register WPS service in Twitcher OWS Proxy<jupyter_code>service = twitcher.register_service(name="emu_demo", url="http://localhost:5000/wps")
service<jupyter_output><empty_output><jupyter_text>WPS GetCapabilities request<jupyter_code>import requests

url = "{}/ows/proxy/emu_demo?service=WPS&request=GetCapabilities".format(base_url)
url
resp = requests.get(url, verify=False)
resp.ok<jupyter_output><empty_output><jupyter_text>WPS DescribeProcess request<jupyter_code>url = "{}/ows/proxy/emu_demo?service=WPS&version=1.0.0&request=DescribeProcess&identifier=hello".format(base_url)
url
resp = requests.get(url, verify=False)
resp.ok<jupyter_output><empty_output><jupyter_text>WPS Execute request ... restricted access<jupyter_code>url = "{}/ows/proxy/emu_demo?service=WPS&version=1.0.0&request=Execute&identifier=hello&DataInputs=name=Tux".format(base_url)
url
resp = requests.get(url, verify=False)
resp.ok<jupyter_output><empty_output><jupyter_text>Access forbidden without access token.<jupyter_code>'AccessForbidden' in resp.text<jupyter_output><empty_output><jupyter_text>Get Access token for compute<jupyter_code>compute_token = twitcher.fetch_token(client_id=client['client_id'], client_secret=client['client_secret'], scope='compute')
compute_token<jupyter_output><empty_output><jupyter_text>Add access token to parameters<jupyter_code>url = "{}/ows/proxy/emu_demo?service=WPS&version=1.0.0&request=Execute&identifier=hello&DataInputs=name=Tux&access_token={}".format(
        base_url, compute_token['access_token'])
url
resp = requests.get(url, verify=False)
resp.ok
'Hello Tux' in resp.text<jupyter_output><empty_output><jupyter_text>... or add access token to headers<jupyter_code>headers = {'Authorization': 'Bearer {}'.format(compute_token['access_token'])}
headers
resp = requests.get(
    "{}/ows/proxy/emu_demo?service=WPS&version=1.0.0&request=Execute&identifier=hello&DataInputs=name=Tux".format(base_url),
    headers=headers,
    verify=False)
'Hello Tux' in resp.text<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13618368962787014, 'fraction_numerical': 0.009501187648456057, 'mean_word_length': 11.090909090909092, 'pattern_counts': {'":': 0, '<': 42, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '585660', 'license': 'Apache-2.0', 'n_tokens_mistral': 898, 'n_tokens_neox': 896, 'n_words': 111, 'path': 'notebooks/twitcher-client.ipynb', 'repo_name': 'bird-house/twitcher', 'size': '2520'}