Skip to content

KafkaSchema API#

You can obtain a KafkaApi handle via Project.get_kafka_api. Once you have it, you can manage Kafka schemas using the KafkaApi methods:

create_schema #

create_schema(
    subject: str, schema: dict
) -> kafka_schema.KafkaSchema

Create a new kafka schema.

import hopsworks

project = hopsworks.login()

kafka_api = project.get_kafka_api()

avro_schema = {
  "type": "record",
  "name": "tutorial",
  "fields": [
    {
      "name": "id",
      "type": "int"
    },
    {
      "name": "data",
      "type": "string"
    }
  ]
}

kafka_topic = kafka_api.create_schema("my_schema", avro_schema)
PARAMETER DESCRIPTION
subject

Subject name of the schema.

TYPE: str

schema

Avro schema definition.

TYPE: dict

RETURNS DESCRIPTION
kafka_schema.KafkaSchema

The KafkaSchema object.

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request.

get_schema #

get_schema(
    subject: str, version: int
) -> kafka_schema.KafkaSchema | None

Get schema given subject name and version.

PARAMETER DESCRIPTION
subject

Subject name.

TYPE: str

version

Version number.

TYPE: int

RETURNS DESCRIPTION
kafka_schema.KafkaSchema | None

KafkaSchema object or None if it does not exist.

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request.

get_schemas #

get_schemas(subject: str) -> list[kafka_schema.KafkaSchema]

Get all schema versions for the subject.

PARAMETER DESCRIPTION
subject

Subject name.

TYPE: str

RETURNS DESCRIPTION
list[kafka_schema.KafkaSchema]

List of KafkaSchema objects.

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request.

get_subjects #

get_subjects() -> list[str]

Get all subjects.

RETURNS DESCRIPTION
list[str]

List of registered subjects.

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request.

KafkaSchema #

id property #

id

Id of the kafka schema.

schema property #

schema

Schema definition.

subject property #

subject

Name of the subject for the schema.

version property #

version

Version of the schema.

delete #

delete()

Delete the schema.

Potentially dangerous operation

This operation deletes the schema.

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request