Post artifact
Example - Publish a new data artifact via your connector
Last update: 2024-01-27
This request publishes a data artifact on a custom connector using a connection to the connector. It uses a pre-established connection from the examples request to our connector.
The following operations are demonstrated:
Load environment variables (your connector configs) from a .env file.
Establish a connection to your TSG connector.
Load the contract offer from a file.
Publish a data artifact on your connector.
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 publish a data artifact on your connector.
Ensure that the required parameters are specified before executing the request:
artifact_path: The path to the data artifact.
artifact_description: The description of the data artifact.
artifact_title: The title of the data artifact.
contract_offer_path: The path to the contract offer file.
catalog_id (Optional): The id of the catalog to add the artificat. If the catalog does not exist it will be created
1
2
3if __name__ == "__main__":
4 from loguru import logger
5 from dotenv import dotenv_values
6 from tsg_client.controllers import TSGController
7
8 # Comment the line below to enable internal logger:
9 logger.disable("")
10
11 # Load environment variables:
12 config = dotenv_values('.env')
13
14 # Connect to our TSG connector:
15 conn = TSGController(
16 api_key=config['API_KEY'],
17 connector_id=config['CONNECTOR_ID'],
18 access_url=config['ACCESS_URL'],
19 agent_id=config['AGENT_ID']
20 )
21
22 # Specify the required parameters:
23 artifact_path = ".files/artifacts/default.json"
24 artifact_description = "Example artifact (default) - TSG Client"
25 artifact_title = "TSG-Client Example"
26 contract_offer_path = "./files/contracts/default.json"
27
28 # Read the contract offer content from the file:
29 with open(contract_offer_path, 'r') as file:
30 contract_offer_content = file.read()
31
32 with open(artifact_path, 'r') as file:
33 artifact_content = file.read()
34
35 # Post artifact on our connector:
36 data_artifact = conn.publish_data_artifact(
37 artifact=artifact_content,
38 contract_offer=contract_offer_content,
39 description=artifact_description,
40 title=artifact_title,
41 # catalog_id="resources" # OPTIONAL
42 )
43
44 print("-" * 79)
45 print("Data Artifact:")
46 print(data_artifact)