Python API - Dataset Shares
I'm wondering how to find all of the projects that are "receiving" shared datasets from a project (very similar to the graph project view) using Python.
For example, if I'm sharing Dataset A from Project 1 to Project 2 and Project 3, I'd like to be able to do something like:
project = client.get_project('project1')
shares = project.get_dependent_projects() # return a list showing that Dataset A is shared with P2 and P3
Is there a way to do this?
Thanks!
Best Answer
-
Ignacio_Toledo Dataiku DSS Core Designer, Dataiku DSS Core Concepts, Neuron 2020, Neuron, Registered, Dataiku Frontrunner Awards 2021 Finalist, Neuron 2021, Neuron 2022, Frontrunner 2022 Finalist, Frontrunner 2022 Winner, Dataiku Frontrunner Awards 2021 Participant, Frontrunner 2022 Participant, Neuron 2023 Posts: 415 Neuron
Hi @rmoore
. What I've been using is this code:shared = {}
project = client.get_project('project1')
exposed = project.get_settings().settings['exposedObjects']['objects']
for e in exposed:
if e['type'] == "DATASET":
name = e['localName']
rules = e['rules']
shared[name] = []
for r in rules:
proj = r['targetProject']
print(f'Dataset {name} is exposed in Project {proj}')
shared[name].append(proj)This get you a dictionary, with one 'key' by shared dataset, and the values of the dictionary are the lists with the name of the projects that have access to a particular dataset.
I choose a dictionary, because I've some projects with multiple datasets being shared. For example, one output for me is:
{'datas_array_ebs': ['NEWDSAALGORITHM'], 'fieldsource': ['SPECIFICPARSING'], 'datas_projects': ['LASANALYSIS'], 'datas_sb_status': ['CONESEARCHES', 'DUPLICATION_CHECKS'], 'datas_schedblocks': ['CONESEARCHES', 'C7ACTIVESBSQA0QUERIES'], 'datas_aqua_execblock': ['C7ACTIVESBSQA0QUERIES'], 'PROJECTS_SQL': ['CYCLECOMPLETIONMONITORING'], 'SCHEDBLOCKS_SQL': ['CYCLECOMPLETIONMONITORING'], 'SB_STATUS_SQL': ['CYCLECOMPLETIONMONITORING'], 'SBLOCKS_SQL': ['CYCLECOMPLETIONMONITORING'], 'SCIENCEGOALS_SQL': ['CYCLECOMPLETIONMONITORING'], 'TARGET_TABLES_SQL': ['CYCLECOMPLETIONMONITORING'], 'AQUA_EXECBLOCK_SQL': ['CYCLECOMPLETIONMONITORING'], 'EXECUTIVE_SHARE_SQL': ['CYCLECOMPLETIONMONITORING'], 'PROJECT_ASSIGNMENTS': ['CONESEARCHES', 'P2GDATAFORCYCLE7PROJECTS', 'DAILYTRACKASAC', 'ARCANDRESTEST'], 'datas_target_tables': ['CONESEARCHES']}