isogeo_pysdk.utils module

Complementary set of utils to use with Isogeo API.

class isogeo_pysdk.utils.IsogeoUtils(proxies={})

Bases: object

Complementary set of utilitary methods and functions to make it easier using Isogeo API.

API_URLS = {'prod': 'api', 'qa': ''}
APP_URLS = {'prod': '', 'qa': ''}
CSW_URLS = {'prod': '', 'qa': ''}
MNG_URLS = {'prod': '', 'qa': ''}
OC_URLS = {'prod': '', 'qa': ''}
WEBAPPS = {'csw_getcap': {'args': ('share_id', 'share_token'), 'url': '{share_id}/{share_token}?service=CSW&version=2.0.2&request=GetCapabilities'}, 'csw_getrec': {'args': ('md_uuid_urn', 'share_id', 'share_token'), 'url': '{share_id}/{share_token}?service=CSW&version=2.0.2&request=GetRecordById&id={md_uuid_urn}&elementsetname=full&outputSchema='}, 'csw_getrecords': {'args': ('share_id', 'share_token'), 'url': '{share_id}/{share_token}?service=CSW&version=2.0.2&request=GetRecords&ResultType=results&ElementSetName=brief&maxRecords=20&OutputFormat=application/xml&OutputSchema='}, 'oc': {'args': ('md_id', 'share_id', 'share_token'), 'url': '{share_id}/{share_token}/r/{md_id}'}, 'pixup_portal': {'args': ('md_id', 'portal_url'), 'url': 'http://{portal_url}/?muid={md_id}'}}
classmethod cache_clearer(only_already_hit=1)

Clear all LRU cached functions.

Parameters:only_already_hit (bool) – option to clear cache only for functions which have been already hit. Defaults to True.
classmethod convert_octets(octets)

Convert a mount of octets in readable size.

Parameters:octets (int) – mount of octets to convert
Return type:str
classmethod convert_uuid(in_uuid=<class 'str'>, mode=0)

Convert a metadata UUID to its URI equivalent. And conversely.

  • in_uuid (str) – UUID or URI to convert
  • mode (int) –

    conversion direction. Options:

    • 0 to HEX
    • 1 to URN (RFC4122)
    • 2 to URN (Isogeo specific style)
classmethod credentials_loader(in_credentials='client_secrets.json')

Loads API credentials from a file, JSON or INI.

Parameters:in_credentials (str) – path to the credentials file. By default, ./client_secrets.json
Return type:dict
Returns:a dictionary with credentials (ID, secret, URLs, platform…)
api_credentials = IsogeoUtils.credentials_loader("./_auth/client_secrets.json")
>>> {
        'auth_mode': 'group',
        'client_id': 'python-minimalist-sdk-test-uuid-1a2b3c4d5e6f7g8h9i0j11k12l',
        'client_secret': 'application-secret-1a2b3c4d5e6f7g8h9i0j11k12l13m14n15o16p17Q18rS',
        'kind': None,
        'platform': 'prod',
        'scopes': ['resources:read'],
        'staff': None,
        'type': None,
        'uri_auth': '',
        'uri_base': '',
        'uri_redirect': None,
        'uri_token': ''
classmethod encoded_words_to_text(in_encoded_words)

Pull out the character set, encoding, and encoded text from the input encoded words. Next, it decodes the encoded words into a byte string, using either the quopri module or base64 module as determined by the encoding. Finally, it decodes the byte string using the character set and returns the result.


Parameters:in_encoded_words (str) – base64 or quori encoded character string.
get_edit_url(metadata, tab='identification')

Returns the edition URL of a metadata.

  • metadata (Metadata) – metadata
  • tab (str) – target tab in the web form. Optionnal. Defaults to ‘identification’.
Return type:


get_isogeo_version(component='api', prot='https')

Get Isogeo components versions. Authentication not required.

Parameters:component (str) –

which platform component. Options:

  • api [default]
  • db
  • app
get_request_base_url(route, prot='https')

Build the request url for the specified route.

  • route (str) – route to format
  • prot (str) – https [DEFAULT] or http
Return type:


classmethod get_url_base_from_url_token(url_api_token='')

Returns the Isogeo API root URL (not included into credentials file) from the token or the auth URL (always included).

Parameters:str (url_api_token) – url to Isogeo API ID token generator
Return type:str
>>> ""
>>> ""
get_view_url(webapp='oc', **kwargs)

Constructs the view URL of a metadata.

  • webapp (str) – web app destination
  • kwargs (dict) – web app specific parameters. For example see WEBAPPS
classmethod guess_platform_from_url(url='')

Returns the Isogeo platform from a given URL.

Parameters:str (url) – URL string to guess from
Return type:str
Returns:“prod” or “qa” or “unknown”
>>> "prod"
>>> "qa"
>>> "unknown"
classmethod hlpr_datetimes(in_date, try_again=1)

Helper to handle differnts dates formats. See:

  • raw_object (dict) – metadata dictionary returned by a request.json()
  • try_again (bool) – iterations on the method

a correct datetime object

Return type:


# for an event date
>>> 2018-06-04 00:00:00
# for a metadata creation date with 6 digits as milliseconds
>>> 2019-05-17 13:01:08.559123
# for a metadata creation date with more than 6 digits as milliseconds
>>> 2019-06-13 16:21:38.191761
lang = 'fr'
classmethod pages_counter(total, page_size=100)

Simple helper to handle pagination. Returns the number of pages for a given number of results.

  • total (int) – count of metadata in a search request
  • page_size (int) – count of metadata to display in each page
Return type:


register_webapp(webapp_name, webapp_args, webapp_url)

Register a new WEBAPP to use with the view URL builder.

  • webapp_name (str) – name of the web app to register
  • webapp_args (list) – dynamic arguments to complete the URL. Typically ‘md_id’.
  • webapp_url (str) – URL of the web app to register with args tags to replace. Example: ‘{md_id}’

Set Isogeo base URLs according to platform.

Parameters:platform (str) –

platform to use. Options:

  • prod [DEFAULT]
  • qa
  • int
classmethod set_lang_and_locale(lang)

Set requests language and the matching locale.

Parameters:lang (str) – language code to set API localization (“en” or “fr”). Defaults to ‘fr’.
tags_to_dict(tags=<class 'dict'>, prev_query=<class 'dict'>, duplicated='rename')

Reverse search tags dictionary to values as keys. Useful to populate filters comboboxes for example.

  • tags (dict) – tags dictionary from a search request
  • prev_query (dict) – query parameters returned after a search request. Typically search.get(“query”).
  • duplicated (str) –

    what to do about duplicated tags label. Values:

    • ignore - last tag parsed survives
    • merge - add duplicated in value as separated list (sep = ‘||’)
    • rename [default] - if duplicated tag labels are part of different workgroup, so the tag label is renamed with workgroup.