Google Cloud Datacatalog API client library for data discovery and metadata management
—
Import and export capabilities for taxonomies, enabling cross-regional taxonomy management, backup/restore operations, and taxonomy sharing between organizations.
Serialize taxonomies to/from a structured format for backup, migration, or cross-regional deployment of data governance policies.
def export_taxonomies(
self,
request: ExportTaxonomiesRequest = None,
*,
parent: str = None,
taxonomies: Sequence[str] = None,
**kwargs
) -> ExportTaxonomiesResponse:
"""
Export taxonomies in the specified project in a serialized format.
Args:
request: The request object
parent: str - Required. Format: projects/{project}/locations/{location}
taxonomies: Sequence[str] - Required. Resource names of taxonomies to export
Returns:
ExportTaxonomiesResponse: Serialized taxonomies
Raises:
google.api_core.exceptions.NotFound: One or more taxonomies not found
google.api_core.exceptions.PermissionDenied: Insufficient permissions
"""
def import_taxonomies(
self,
request: ImportTaxonomiesRequest = None,
*,
parent: str = None,
inline_source: InlineSource = None,
cross_regional_source: CrossRegionalSource = None,
**kwargs
) -> ImportTaxonomiesResponse:
"""
Import serialized taxonomies into a specified project.
Args:
request: The request object
parent: str - Required. Format: projects/{project}/locations/{location}
inline_source: InlineSource - Optional. Inline serialized taxonomies
cross_regional_source: CrossRegionalSource - Optional. Cross-regional source
Returns:
ImportTaxonomiesResponse: Imported taxonomies
Raises:
google.api_core.exceptions.InvalidArgument: Invalid serialized data
google.api_core.exceptions.AlreadyExists: Taxonomy with same name exists
"""
def replace_taxonomy(
self,
request: ReplaceTaxonomyRequest = None,
*,
name: str = None,
serialized_taxonomy: SerializedTaxonomy = None,
**kwargs
) -> Taxonomy:
"""
Replace an existing taxonomy with a serialized taxonomy.
Args:
request: The request object
name: str - Required. Format: projects/{project}/locations/{location}/taxonomies/{taxonomy}
serialized_taxonomy: SerializedTaxonomy - Required. Serialized taxonomy data
Returns:
Taxonomy: The replaced taxonomy
Raises:
google.api_core.exceptions.NotFound: Taxonomy not found
google.api_core.exceptions.InvalidArgument: Invalid serialized data
"""Usage Example:
from google.cloud import datacatalog_v1
client = datacatalog_v1.PolicyTagManagerSerializationClient()
# Export taxonomies
taxonomy_names = [
"projects/source-project/locations/us-central1/taxonomies/data-sensitivity",
"projects/source-project/locations/us-central1/taxonomies/data-retention"
]
export_request = datacatalog_v1.ExportTaxonomiesRequest(
parent="projects/source-project/locations/us-central1",
taxonomies=taxonomy_names
)
export_response = client.export_taxonomies(request=export_request)
# Import taxonomies to another project
import_request = datacatalog_v1.ImportTaxonomiesRequest(
parent="projects/target-project/locations/us-east1",
inline_source=datacatalog_v1.InlineSource(
taxonomies=export_response.taxonomies
)
)
import_response = client.import_taxonomies(request=import_request)
print(f"Imported {len(import_response.taxonomies)} taxonomies")
for taxonomy in import_response.taxonomies:
print(f"- {taxonomy.display_name}: {taxonomy.name}")class ExportTaxonomiesRequest:
parent: str # Required parent location
taxonomies: Sequence[str] # Required taxonomy resource names
serialized_taxonomies: bool # Optional. Include serialized format
class ImportTaxonomiesRequest:
parent: str # Required parent location
inline_source: InlineSource # Optional inline source
cross_regional_source: CrossRegionalSource # Optional cross-regional source
class ReplaceTaxonomyRequest:
name: str # Required taxonomy name
serialized_taxonomy: SerializedTaxonomy # Required serialized taxonomyclass ExportTaxonomiesResponse:
taxonomies: Sequence[SerializedTaxonomy] # Exported taxonomies
class ImportTaxonomiesResponse:
taxonomies: Sequence[Taxonomy] # Imported taxonomiesclass InlineSource:
"""Inline source for serialized taxonomies."""
taxonomies: Sequence[SerializedTaxonomy] # Serialized taxonomies
class CrossRegionalSource:
"""Cross-regional source for taxonomies."""
taxonomy: str # Source taxonomy resource name
project: str # Source project ID
location: str # Source location
class SerializedTaxonomy:
"""Serialized representation of a taxonomy."""
display_name: str # Taxonomy display name
description: str # Taxonomy description
policy_tags: Sequence[SerializedPolicyTag] # Policy tags
activated_policy_types: Sequence[Taxonomy.PolicyType] # Activated policy types
class SerializedPolicyTag:
"""Serialized representation of a policy tag."""
policy_tag: str # Policy tag identifier
display_name: str # Policy tag display name
description: str # Policy tag description
child_policy_tags: Sequence[str] # Child policy tag identifiersInstall with Tessl CLI
npx tessl i tessl/pypi-google-cloud-datacatalog