Create taxonomy
Stay organized with collections
Save and categorize content based on your preferences.
Create a new taxonomy.
Code sample
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis page provides code samples in Go, Node.js, and Python for creating a new taxonomy within Google Cloud Data Catalog.\u003c/p\u003e\n"],["\u003cp\u003eThe code samples illustrate how to define a taxonomy's display name, description, and its validity for fine-grained access control.\u003c/p\u003e\n"],["\u003cp\u003eSetting up Application Default Credentials is required for authenticating with the Data Catalog, as mentioned in the documentation and code comments for all samples.\u003c/p\u003e\n"],["\u003cp\u003eEach code example references its respective language-specific setup instructions and API documentation for further details on using Google Cloud Data Catalog.\u003c/p\u003e\n"]]],[],null,["# Create taxonomy\n\nCreate a new taxonomy.\n\nCode sample\n-----------\n\n### Go\n\n\nBefore trying this sample, follow the Go setup instructions in the\n[Data Catalog quickstart using\nclient libraries](/data-catalog/docs/reference/libraries).\n\n\nFor more information, see the\n[Data Catalog Go API\nreference documentation](https://godoc.org/cloud.google.com/go/datacatalog).\n\n\nTo authenticate to Data Catalog, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n import (\n \t\"context\"\n \t\"fmt\"\n \t\"io\"\n\n \tdatacatalog \"cloud.google.com/go/datacatalog/apiv1beta1\"\n \t\"cloud.google.com/go/datacatalog/apiv1beta1/datacatalogpb\"\n )\n\n // createTaxonomy creates a taxonomy resource, which holds the collection of policy tags.\n //\n // This example marks the taxonomy as valid for defining fine grained access control, also\n // known as column-level access control when used in conjunction with BigQuery.\n func createTaxonomy(w io.Writer, projectID, location, displayName string) (string, error) {\n \t// projectID := \"my-project-id\"\n \t// location := \"us\"\n \t// displayName := \"example-taxonomy\"\n \tctx := context.Background()\n \tpolicyClient, err := datacatalog.NewPolicyTagManagerClient(ctx)\n \tif err != nil {\n \t\treturn \"\", fmt.Errorf(\"datacatalog.NewPolicyTagManagerClient: %w\", err)\n \t}\n \tdefer policyClient.Close()\n\n \treq := &datacatalogpb.CreateTaxonomyRequest{\n \t\tParent: fmt.Sprintf(\"projects/%s/locations/%s\", projectID, location),\n \t\tTaxonomy: &datacatalogpb.Taxonomy{\n \t\t\tDisplayName: displayName,\n \t\t\tDescription: \"Taxonomy created via basic snippet testing\",\n \t\t\tActivatedPolicyTypes: []datacatalogpb.Taxonomy_PolicyType{\n \t\t\t\tdatacatalogpb.https://cloud.google.com/go/docs/reference/cloud.google.com/go/datacatalog/latest/apiv1beta1/datacatalogpb.html#cloud_google_com_go_datacatalog_apiv1beta1_datacatalogpb_Taxonomy_POLICY_TYPE_UNSPECIFIED_Taxonomy_FINE_GRAINED_ACCESS_CONTROL,\n \t\t\t},\n \t\t},\n \t}\n \tresp, err := policyClient.CreateTaxonomy(ctx, req)\n \tif err != nil {\n \t\treturn \"\", fmt.Errorf(\"CreateTaxonomy: %w\", err)\n \t}\n\n \tfmt.Fprintf(w, \"Taxonomy %s was created.\\n\", resp.Name)\n \treturn resp.Name, nil\n }\n\n### Node.js\n\n\nBefore trying this sample, follow the Node.js setup instructions in the\n[Data Catalog quickstart using\nclient libraries](/data-catalog/docs/reference/libraries).\n\n\nFor more information, see the\n[Data Catalog Node.js API\nreference documentation](https://googleapis.dev/nodejs/datacatalog/latest/index.html).\n\n\nTo authenticate to Data Catalog, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n // Import the Google Cloud client library.\n const {DataCatalogClient, PolicyTagManagerClient} =\n require('https://cloud.google.com/nodejs/docs/reference/datacatalog/latest/overview.html').v1;\n const dataCatalog = new https://cloud.google.com/nodejs/docs/reference/datacatalog/latest/overview.html();\n const policyTagManager = new https://cloud.google.com/nodejs/docs/reference/datacatalog/latest/overview.html();\n\n async function createTaxonomy() {\n // const location = 'us';\n /**\n * TODO(developer): Uncomment the following lines before running the sample.\n */\n // const projectId = 'my_project'; // Google Cloud Platform project\n // const location = 'us'\n // const displayName = 'my_display_name'; // Display name for new taxonomy.\n\n // Parent project location format is `projects/${projectId}/locations/${location}`\n const parent = dataCatalog.locationPath(projectId, location);\n\n const request = {\n parent: parent,\n taxonomy: {\n displayName: displayName,\n activatedPolicyTypes: ['FINE_GRAINED_ACCESS_CONTROL'],\n },\n };\n\n try {\n const [metadata] = await policyTagManager.createTaxonomy(request);\n console.log(`Created taxonomy: ${metadata.name}`);\n } catch (e) {\n console.error(e);\n process.exitCode = 1;\n }\n }\n\n### Python\n\n\nBefore trying this sample, follow the Python setup instructions in the\n[Data Catalog quickstart using\nclient libraries](/data-catalog/docs/reference/libraries).\n\n\nFor more information, see the\n[Data Catalog Python API\nreference documentation](/python/docs/reference/datacatalog/latest).\n\n\nTo authenticate to Data Catalog, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n from google.cloud import https://cloud.google.com/python/docs/reference/datacatalog/latest/\n\n\n def create_taxonomy(\n # TODO(developer): Set project_id to the ID of the project the\n # taxonomy will belong to.\n project_id: str = \"your-project-id\",\n # TODO(developer): Specify the geographic location where the\n # taxonomy should reside.\n location_id: str = \"us\",\n # TODO(developer): Set the display name of the taxonomy.\n display_name: str = \"example-taxonomy\",\n ):\n # TODO(developer): Construct a Policy Tag Manager client object. To avoid\n # extra delays due to authentication, create a single client for your\n # program and share it across operations.\n client = https://cloud.google.com/python/docs/reference/datacatalog/latest/.https://cloud.google.com/python/docs/reference/datacatalog/latest/google.cloud.datacatalog_v1.services.policy_tag_manager.PolicyTagManagerClient.html()\n\n # Construct a full location path to be the parent of the taxonomy.\n parent = https://cloud.google.com/python/docs/reference/datacatalog/latest/.https://cloud.google.com/python/docs/reference/datacatalog/latest/google.cloud.datacatalog_v1.services.policy_tag_manager.PolicyTagManagerClient.html.common_location_path(\n project_id, location_id\n )\n\n # TODO(developer): Construct a full Taxonomy object to send to the API.\n taxonomy = https://cloud.google.com/python/docs/reference/datacatalog/latest/.https://cloud.google.com/python/docs/reference/datacatalog/latest/google.cloud.datacatalog_v1.types.Taxonomy.html()\n taxonomy.display_name = display_name\n taxonomy.description = \"This Taxonomy represents ...\"\n\n # Send the taxonomy to the API for creation.\n taxonomy = client.https://cloud.google.com/python/docs/reference/datacatalog/latest/google.cloud.datacatalog_v1.services.policy_tag_manager.PolicyTagManagerClient.html#google_cloud_datacatalog_v1_services_policy_tag_manager_PolicyTagManagerClient_create_taxonomy(parent=parent, taxonomy=taxonomy)\n print(f\"Created taxonomy {taxonomy.name}\")\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=data_catalog)."]]