Skip to main content

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?

The openmetadata-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: call configure() 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 /api at the end of the URL, the same as hostPort in 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 an authProvider.

Quick Start: SDK 2.0

Connect with configure(), then create, update, and delete a table:
Fields such as 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 with OpenMetadataConnection, 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 in sslConfig:

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 interactions
  • OpenMetadataConnection: Connection configuration
  • Entity Classes: Type-safe representations of all OpenMetadata entities

Key Methods

  • create_or_update(data): Create or update an entity
  • get_by_name(entity, fqn): Retrieve entity by fully qualified name
  • get_by_id(entity, entity_id): Retrieve entity by ID
  • list_entities(entity, **kwargs): List entities with pagination
  • list_all_entities(entity, **kwargs): Generator for all entities
  • delete(entity, entity_id): Delete an entity
  • health_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

  1. Connection Management: Reuse OpenMetadata client instances
  2. Error Handling: Always handle potential exceptions
  3. Pagination: Use list_all_entities() for large datasets
  4. Performance: Specify only required fields when fetching entities
  5. Resource Cleanup: Call metadata.close() when done