Implementation:Datahub project Datahub Container Key Guid Generator
| Knowledge Sources | |
|---|---|
| Domains | Python_CLI, Metadata_Emission |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
A Python CLI tool that generates DataHub container URNs for database and schema entities using Click and the DataHub MCP builder library.
Description
The Container Key GUID Generator is a command-line utility built with the Click framework that produces deterministic URN identifiers for DataHub container entities. It follows the Strategy pattern through an abstract URNGenerator base class with two concrete implementations:
- DatabaseURNGenerator -- Generates URNs for database containers using
DatabaseKeyfrom the DataHub MCP builder. Requiresplatformanddatabaseparameters, with an optionalinstanceparameter. - SchemaURNGenerator -- Generates URNs for schema containers using
SchemaKeyfrom the DataHub MCP builder. Requiresplatform,database, andschemaparameters, with optionalinstanceandenvparameters.
Both generators perform strict input validation, rejecting unknown or missing fields with descriptive error messages. The tool supports two output formats: plain text (default) and JSON, which includes the URN, container type, and input parameters.
Usage
Use this script when you need to deterministically generate container URNs outside of the normal ingestion pipeline, for example during testing, debugging, or manual metadata operations. It is especially useful for verifying the URN format that the Java SDK or Python ingestion framework would produce for a given set of container key parameters.
Code Reference
Source Location
metadata-integration/java/datahub-client/scripts/container_key_guid_generator.py
Signature
class URNGenerator(ABC):
@abstractmethod
def generate(self, args: Dict[str, Any]) -> str: ...
class DatabaseURNGenerator(URNGenerator):
def generate(self, args: Dict[str, Any]) -> str: ...
class SchemaURNGenerator(URNGenerator):
def generate(self, args: Dict[str, Any]) -> str: ...
def validate_key_value(ctx, param, value) -> dict: ...
@click.command()
def generate_urn(container_type: str, param: Dict[str, str], output_format: str): ...
Import
from datahub.emitter.mcp_builder import DatabaseKey, SchemaKey
import click
I/O Contract
Inputs
| Parameter | Type | Required | Description |
|---|---|---|---|
--container-type |
Choice: database, schema |
Yes | The type of container URN to generate |
--param / -p |
Multiple key=value pairs | Yes | Container key fields (e.g., -p platform=mysql -p database=mydb)
|
--output-format |
Choice: text, json |
No (default: text) |
Controls whether output is a plain URN string or a JSON object |
Database container required params: platform, database; optional: instance
Schema container required params: platform, database, schema; optional: instance, env
Outputs
- Text format: A single URN string printed to stdout (e.g.,
urn:li:container:...) - JSON format: A JSON object containing
urn,container_type, andparametersfields
Usage Examples
# Generate a database container URN
python container_key_guid_generator.py --container-type database \
-p platform=test-platform -p instance=DEV -p database=test-database
# Generate a schema container URN with JSON output
python container_key_guid_generator.py --container-type schema \
-p platform=mysql -p database=mydb -p schema=public --output-format json
JSON output example:
{
"urn": "urn:li:container:...",
"container_type": "schema",
"parameters": {
"platform": "mysql",
"database": "mydb",
"schema": "public"
}
}
Related Pages
- Datahub_project_Datahub_KafkaEmitter -- Java Kafka-based metadata emitter
- Datahub_project_Datahub_S3Emitter -- Java S3-based metadata emitter