Skip to content

KafkaSchema API#

Handle#

[source]

get_kafka_api#

Project.get_kafka_api()

Get the kafka api for the project.

Returns

KafkaApi: The Kafka Api handle


Creation#

[source]

create_schema#

KafkaApi.create_schema(subject, schema)

Create a new kafka schema.

import hopsworks

connection = hopsworks.connection()

project = connection.get_project()

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)
Arguments

  • subject str: subject name of the schema
  • schema dict: avro schema definition

Returns

KafkaSchema: The KafkaSchema object

Raises

  • RestAPIError: If unable to create the schema

Retrieval#

[source]

get_schema#

KafkaApi.get_schema(subject, version)

Get schema given subject name and version.

Arguments

  • subject str: subject name
  • version int: version number

Returns

KafkaSchema: KafkaSchema object

Raises

  • RestAPIError: If unable to get the schema

[source]

get_schemas#

KafkaApi.get_schemas(subject)

Get all schema versions for the subject.

Arguments

  • subject str: subject name

Returns

List[KafkaSchema]: List of KafkaSchema objects

Raises

  • RestAPIError: If unable to get the schemas

[source]

get_subjects#

KafkaApi.get_subjects()

Get all subjects.

Returns

List[str]: List of registered subjects

Raises

  • RestAPIError: If unable to get the subjects

Properties#

[source]

id#

Id of the kafka schema


[source]

schema#

Schema definition


[source]

subject#

Name of the subject for the schema


[source]

version#

Version of the schema


Methods#

[source]

delete#

KafkaSchema.delete()

Delete the schema

Potentially dangerous operation

This operation deletes the schema.

Raises

RestAPIError.