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:

Quick Start

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

Custom Configuration

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