Python SDK
The OpenMetadata Python SDK provides a comprehensive interface for interacting with the OpenMetadata API. It offers type-safe operations for managing metadata entities and seamless integration with your Python applications.Installation
Install the OpenMetadata Python SDK using pip:Which Python SDK Should I Use?
Theopenmetadata-ingestion package contains two Python clients. Both talk to the same OpenMetadata API.
For new scripts and jobs, use SDK 2.0. It needs less setup and reads more simply. Use the original client when you need an operation that SDK 2.0 doesn’t offer yet, or when you maintain existing code that already uses it.
Using Both Clients in One Script
Both ship in the same package, so one script can use both. Set up each one separately: callconfigure() for SDK 2.0 and build an OpenMetadata client for the original client.
Migrating an Existing Job
Change one call at a time:Tables.create(request) also updates an existing table, the same as create_or_update.
Three details differ from what you might expect:
- In
configure(host=...), include/apiat the end of the URL, the same ashostPortin the original client. - When you list entities, pass query filters as
filters={"databaseSchema": "service.database.schema"}and read the results from.entities. - With the original client, set
authProvider="openmetadata"when you authenticate with a JWT token. SDK 2.0 doesn’t need anauthProvider.
Quick Start: SDK 2.0
Connect withconfigure(), then create, update, and delete a table:
name, id, and fullyQualifiedName are wrapper objects. Use .root to get the plain value, for example table.fullyQualifiedName.root.
Call configure() with no arguments to read OPENMETADATA_HOST and OPENMETADATA_JWT_TOKEN from your environment.
Quick Start: Original Client
Connect withOpenMetadataConnection, then read and update entities:
Basic Connection
Working with Entities
Core Functionality
Entity Management
The Python SDK provides full CRUD operations for all OpenMetadata entities:Create or Update Entities
Retrieve Entities
List All Entities
Entity References
Advanced Features
Validating a Custom Certificate Authority (CA) Certificate
To trust a private CA, pass the path to its certificate insslConfig:
Error Handling
Working with Versions
Common Use Cases
Data Discovery
Metadata Automation
Lineage Management
API Reference
The Python SDK provides a comprehensive API based on the OpenMetadata data model:Core Classes
OpenMetadata: Main client class for API interactionsOpenMetadataConnection: Connection configuration- Entity Classes: Type-safe representations of all OpenMetadata entities
Key Methods
create_or_update(data): Create or update an entityget_by_name(entity, fqn): Retrieve entity by fully qualified nameget_by_id(entity, entity_id): Retrieve entity by IDlist_entities(entity, **kwargs): List entities with paginationlist_all_entities(entity, **kwargs): Generator for all entitiesdelete(entity, entity_id): Delete an entityhealth_check(): Check API connectivity
Type Safety
The Python SDK is built on generated Pydantic models, providing:- Type hints for better IDE support
- Runtime validation of data structures
- Auto-completion for entity properties
- Error prevention through static typing
Best Practices
- Connection Management: Reuse OpenMetadata client instances
- Error Handling: Always handle potential exceptions
- Pagination: Use
list_all_entities()for large datasets - Performance: Specify only required fields when fetching entities
- Resource Cleanup: Call
metadata.close()when done