KafkaSchema API#
Handle#
get_kafka_api#
Project.get_kafka_api()
Get the kafka api for the project.
Returns
KafkaApi: The Kafka Api handle
Creation#
create_schema#
KafkaApi.create_schema(subject, schema)
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)
- subject
str: subject name of the schema - schema
dict: avro schema definition
Returns
KafkaSchema: The KafkaSchema object
Raises
hopsworks.client.exceptions.RestAPIError: If the backend encounters an error when handling the request
Retrieval#
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 or None if it does not exist.
Raises
hopsworks.client.exceptions.RestAPIError: If the backend encounters an error when handling the request
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
hopsworks.client.exceptions.RestAPIError: If the backend encounters an error when handling the request
get_subjects#
KafkaApi.get_subjects()
Get all subjects.
Returns
List[str]: List of registered subjects
Raises
hopsworks.client.exceptions.RestAPIError: If the backend encounters an error when handling the request
Properties#
id#
Id of the kafka schema
schema#
Schema definition
subject#
Name of the subject for the schema
version#
Version of the schema
Methods#
delete#
KafkaSchema.delete()
Delete the schema
Potentially dangerous operation
This operation deletes the schema.
Raises
hopsworks.client.exceptions.RestAPIError: If the backend encounters an error when handling the request