Package: purviewautomation
Welcome to Purview Automation!Purview Automation is a Python library designed to be simple to use and makes scaling and automating Azure Purview easier.Create, delete, scale, rollback and automate Purview collections and delete assets in collections. More to come later on!Rather see a video on how it works? See:Purview Automation Video.Documentation:https://purviewautomation.netlify.appSource Code:https://github.com/Ludwinic1/purviewautomationKey benefits:Easy: Create and delete collections and collection hierarchies with one line of codeRollback: Rollback to previous collection hierarchy states and save versions for later useDeploy: Extract existing collections and deploy to UAT/PROD environments ensuring consistency across PurviewsDelete Assets: Delete all assets in a collection or all assets under a collection hierarchySafe: DoesNOTsupercede any Purview permissions. Unable to create/delete collections unless the Collection Admin role is assigned in Purview. See:Purview Roles.Ease of Use: Use either the friendly or actual collection name instead of being required to find the under the hood collection name (actual name). See:Purview Collection Names OverviewExample Showcase:Azure Purview before:Write simple code:client.create_collections(start_collection="My-Collection",collection_names="Sub Collection 1/Deeper Sub 1/Deeper Sub 2/Deeper Sub 3")Azure Purview after:InstallationpipinstallpurviewautomationQuick StartConnect to Purview With a Service PrincipalCreate a Python filemain.py(can be called anything), gather the Azure Service Principal information and replaceyourtenantid,yourclientid,yourclientsecretandyourpurviewaccountname:frompurviewautomationimport(ServicePrincipalAuthentication,PurviewCollections)auth=ServicePrincipalAuthentication(tenant_id="yourtenantid",client_id="yourclientid",client_secret="yourclientsecret")client=PurviewCollections(purview_account_name="yourpurviewaccountname",auth=auth)Important:The Service Principal as to be assigned theCollection Adminrole to a collection in Purview. The below examples assume the Service Principal is assigned the role at the root collection level. See here for more info:Assign the Service Principal the Collection Admin Role in Purview.To learn how to create a Service Principal, see:Create a Service Principal.Connect to Purview With the Azure-Identity Package Via the Azure CLIAlternatively, to connect with your own credentials or other options (Managed Identity, Environment Credentials, Azure CLI Credentials) instead of the Service Principal, use the Azure-Identity package:pip install azure-identityThen sign in with your Azure CLI credentials (in a terminal typeaz loginand sign in via the link that pops up):fromazure.identityimportAzureCliCredentialfrompurviewautomationimportPurviewCollections,AzIdentityAuthenticationauth=AzIdentityAuthentication(credential=AzureCliCredential())client=PurviewCollections(purview_account_name="yourpurviewaccountname",auth=auth)Important:The user or entity has to be assigned theCollection Adminrole to a collection in Purview. The below examples assume the role is assigned at the root collection level. For more info, see:Purview Roles.Now interact with the Purview collections:Print Collectionsprint(client.list_collections())Print Only the Relevant Collection Name Infoclient.list_collections(only_names=True,pprint=True)Return Collections as a List or Only Names as a Dictionarycollection_list=client.list_collections()forcollincollection_list:print(coll)# Return only the relevant names as a dictionarycollection_names=client.list_collections(only_names=True)forname,valueincollection_names.items():print(name,value)# Return just the keys (actual names)fornameincollection_names:print(name)# Return the friendly names or parent collection namesfornameincollection_names.values():friendly_name=name["friendlyName"]parent_name=name["parentCollection"]Create a Collection# Replace "yourpurviewaccountname"client.create_collections(start_collection="yourpurviewaccountname",collection_names="My First Collection")Create a Collection Hierarchy# Create a collection hierarchyclient.create_collections(start_collection="My First Collection",collection_names="Child1/Sub Collection 1/Deeper Sub Collection1")Create Multiple Collections# Both random collections are at the same level under Sub Collection 1client.create_collections(start_collection="Sub Collection 1",collection_names=["Random Collection","Random Collection 2"])Create Multiple Collection Hierarchieshierarchy_1="hierarchy1/hierarchysub1/hierarchysub2/hierarchysub3"hierarchy_2="hierarchy 2/hierarchy sub2"client.create_collections(start_collection="My First Collection",collection_names=[hierarcy_1,hierarchy_2])Delete All Assets in a CollectionImportant:The Service Principal or user that authenticated/connected to Purview would need to be assigned theData Curatorrole on the collection in order to delete assets in that collection. For more info, see:Purview Rolesclient.delete_collection_assets(collection_names="My First Collection")Delete All Assets in Multiple CollectionsImportant:The Service Principal or user that authenticated/connected to Purview would need to be assigned theData Curatorrole on the collection in order to delete assets in that collection. For more info, see:Purview Rolescollections=["Random Collection","hierarchy sub2"]client.delete_collection_assets(collection_names=collections)Extract Collections# Useful for recreating entire collection hierarchies in a new Purview# or saving the output as a version to rollback later# Will output the exact script needed to recreate the entire hierarchyclient.extract_collections("My First Collection")Delete a Collectionclient.delete_collections(collection_names="Random Collection")Delete a Collection with Rollback Enabled# Will delete the collection# and output the exact script needed to recreate the collectionclient.delete_collections(collection_names="Random Collection 2",safe_delete="client")Delete All Assets in a Collection and Delete the CollectionImportant:The Service Principal or user that authenticated/connected to Purview would need to be assigned theData Curatorrole on the collection in order to delete assets in that collection. For more info, see:Purview Roles# Delete all of the assets in the collection# And delete the collection as wellclient.delete_collections("My First Collection",delete_assets=True)Delete a Collection Hierarchy with Rollback Enabled# Will delete all of the children and their children and output the exact script# needed to recreate the entire hierarchy to rollback or deploy to another Purviewclient.delete_collections_reursively("My First Collection",safe_delete="client")Delete All Assets in a Collection Hierarchy and Delete the HierarchyImportant:The Service Principal or user that authenticated/connected to Purview would need to be assigned theData Curatorrole on the collection in order to delete assets in that collection. For more info, see:Purview Roles# Delete all of the assets in all of the collections under the hierarchy# And delete the collection hierarchy as wellclient.delete_collections_recursively("My First Collection",delete_assets=True)