Get external catalogs

Example: Extract catalogs from self-descriptions of an external connector

Last update: 2024-01-27

This request retrieves and prints information about external connector catalogs using a pre-established connection to your TSG connector.

The following operations are demonstrated:

  1. Load environment variables (your connector configs) from a .env file.

  2. Establish a connection to your TSG connector.

  3. Retrieve and print information about external connector self-description

  4. Extract (from self-descriptions) information regarding available catalogs

Important

  • Ensure that the required environment variables (Your Connector API_KEY, CONNECTOR_ID, ACCESS_URL and AGENT_ID) are set in the .env file before using this request.

  • The connector API_KEY can be retrieved by loging into the TSG connector UI and navigating to the ‘API Keys’ tab.

Execute the code below to get your connector self-description catalogs.

 1if __name__ == "__main__":
 2    from pprint import pprint
 3    from loguru import logger
 4    from dotenv import dotenv_values
 5    from tsg_client.controllers import TSGController
 6
 7    # Comment the line below to enable internal logger:
 8    logger.disable("")
 9
10    # Load environment variables:
11    config = dotenv_values('.env')
12
13    # Example of external connector configs (TNO Playground)
14    EXTERNAL_CONNECTOR = {
15        "CONNECTOR_ID": 'urn:playground:tsg:connectors:TestConnector',
16        "ACCESS_URL": 'https://test-connector.playground.dataspac.es',
17        "AGENT_ID": 'urn:playground:tsg:TNO'
18    }
19
20    # Connect to our TSG connector:
21    conn = TSGController(
22        api_key=config['API_KEY'],
23        connector_id=config['CONNECTOR_ID'],
24        access_url=config['ACCESS_URL'],
25        agent_id=config['AGENT_ID']
26    )
27
28    # Get external connector info (self-descriptions):
29    description = conn.get_connector_selfdescription(
30        access_url=EXTERNAL_CONNECTOR['ACCESS_URL'],
31        connector_id=EXTERNAL_CONNECTOR['CONNECTOR_ID'],
32        agent_id=EXTERNAL_CONNECTOR['AGENT_ID']
33    )
34
35    # Get external connector catalogs:
36    catalogs = conn.parse_resource_catalogs(self_description=description)
37
38    print("-" * 79)
39    print(f"> Connector {EXTERNAL_CONNECTOR['CONNECTOR_ID']} Catalogs:")
40    pprint(catalogs)