0
# Taxonomy Serialization
1
2
Import and export capabilities for taxonomies, enabling cross-regional taxonomy management, backup/restore operations, and taxonomy sharing between organizations.
3
4
## Capabilities
5
6
### Taxonomy Import and Export
7
8
Serialize taxonomies to/from a structured format for backup, migration, or cross-regional deployment of data governance policies.
9
10
```python { .api }
11
def export_taxonomies(
12
self,
13
request: ExportTaxonomiesRequest = None,
14
*,
15
parent: str = None,
16
taxonomies: Sequence[str] = None,
17
**kwargs
18
) -> ExportTaxonomiesResponse:
19
"""
20
Export taxonomies in the specified project in a serialized format.
21
22
Args:
23
request: The request object
24
parent: str - Required. Format: projects/{project}/locations/{location}
25
taxonomies: Sequence[str] - Required. Resource names of taxonomies to export
26
27
Returns:
28
ExportTaxonomiesResponse: Serialized taxonomies
29
30
Raises:
31
google.api_core.exceptions.NotFound: One or more taxonomies not found
32
google.api_core.exceptions.PermissionDenied: Insufficient permissions
33
"""
34
35
def import_taxonomies(
36
self,
37
request: ImportTaxonomiesRequest = None,
38
*,
39
parent: str = None,
40
inline_source: InlineSource = None,
41
cross_regional_source: CrossRegionalSource = None,
42
**kwargs
43
) -> ImportTaxonomiesResponse:
44
"""
45
Import serialized taxonomies into a specified project.
46
47
Args:
48
request: The request object
49
parent: str - Required. Format: projects/{project}/locations/{location}
50
inline_source: InlineSource - Optional. Inline serialized taxonomies
51
cross_regional_source: CrossRegionalSource - Optional. Cross-regional source
52
53
Returns:
54
ImportTaxonomiesResponse: Imported taxonomies
55
56
Raises:
57
google.api_core.exceptions.InvalidArgument: Invalid serialized data
58
google.api_core.exceptions.AlreadyExists: Taxonomy with same name exists
59
"""
60
61
def replace_taxonomy(
62
self,
63
request: ReplaceTaxonomyRequest = None,
64
*,
65
name: str = None,
66
serialized_taxonomy: SerializedTaxonomy = None,
67
**kwargs
68
) -> Taxonomy:
69
"""
70
Replace an existing taxonomy with a serialized taxonomy.
71
72
Args:
73
request: The request object
74
name: str - Required. Format: projects/{project}/locations/{location}/taxonomies/{taxonomy}
75
serialized_taxonomy: SerializedTaxonomy - Required. Serialized taxonomy data
76
77
Returns:
78
Taxonomy: The replaced taxonomy
79
80
Raises:
81
google.api_core.exceptions.NotFound: Taxonomy not found
82
google.api_core.exceptions.InvalidArgument: Invalid serialized data
83
"""
84
```
85
86
**Usage Example:**
87
88
```python
89
from google.cloud import datacatalog_v1
90
91
client = datacatalog_v1.PolicyTagManagerSerializationClient()
92
93
# Export taxonomies
94
taxonomy_names = [
95
"projects/source-project/locations/us-central1/taxonomies/data-sensitivity",
96
"projects/source-project/locations/us-central1/taxonomies/data-retention"
97
]
98
99
export_request = datacatalog_v1.ExportTaxonomiesRequest(
100
parent="projects/source-project/locations/us-central1",
101
taxonomies=taxonomy_names
102
)
103
104
export_response = client.export_taxonomies(request=export_request)
105
106
# Import taxonomies to another project
107
import_request = datacatalog_v1.ImportTaxonomiesRequest(
108
parent="projects/target-project/locations/us-east1",
109
inline_source=datacatalog_v1.InlineSource(
110
taxonomies=export_response.taxonomies
111
)
112
)
113
114
import_response = client.import_taxonomies(request=import_request)
115
116
print(f"Imported {len(import_response.taxonomies)} taxonomies")
117
for taxonomy in import_response.taxonomies:
118
print(f"- {taxonomy.display_name}: {taxonomy.name}")
119
```
120
121
## Request Types
122
123
```python { .api }
124
class ExportTaxonomiesRequest:
125
parent: str # Required parent location
126
taxonomies: Sequence[str] # Required taxonomy resource names
127
serialized_taxonomies: bool # Optional. Include serialized format
128
129
class ImportTaxonomiesRequest:
130
parent: str # Required parent location
131
inline_source: InlineSource # Optional inline source
132
cross_regional_source: CrossRegionalSource # Optional cross-regional source
133
134
class ReplaceTaxonomyRequest:
135
name: str # Required taxonomy name
136
serialized_taxonomy: SerializedTaxonomy # Required serialized taxonomy
137
```
138
139
## Response Types
140
141
```python { .api }
142
class ExportTaxonomiesResponse:
143
taxonomies: Sequence[SerializedTaxonomy] # Exported taxonomies
144
145
class ImportTaxonomiesResponse:
146
taxonomies: Sequence[Taxonomy] # Imported taxonomies
147
```
148
149
## Serialization Types
150
151
```python { .api }
152
class InlineSource:
153
"""Inline source for serialized taxonomies."""
154
taxonomies: Sequence[SerializedTaxonomy] # Serialized taxonomies
155
156
class CrossRegionalSource:
157
"""Cross-regional source for taxonomies."""
158
taxonomy: str # Source taxonomy resource name
159
project: str # Source project ID
160
location: str # Source location
161
162
class SerializedTaxonomy:
163
"""Serialized representation of a taxonomy."""
164
display_name: str # Taxonomy display name
165
description: str # Taxonomy description
166
policy_tags: Sequence[SerializedPolicyTag] # Policy tags
167
activated_policy_types: Sequence[Taxonomy.PolicyType] # Activated policy types
168
169
class SerializedPolicyTag:
170
"""Serialized representation of a policy tag."""
171
policy_tag: str # Policy tag identifier
172
display_name: str # Policy tag display name
173
description: str # Policy tag description
174
child_policy_tags: Sequence[str] # Child policy tag identifiers
175
```