SubjectCache

class kafkit.registry.sansio.SubjectCache(schema_cache)

Bases: object

A cache of subjects in a schema registry that maps subject and version tuples to an actual schema.

Parameters:
schema_cache : SchemaCache

A schema cache instance.

Notes

The SubjectCache provides a subject-aware layer over the SchemaCache. While schemas and their IDs are unique in a schema registry, multiple subject-version combinations can point to the same schema-ID combination.

When you insert a schema into the SubjectCache, you are also inserting the schema and schema ID into the member SchemaCache.

Methods Summary

get(subject, version) Get the full set of schema and ID information for a subject version.
get_id(subject, version) Get the schema ID of a subject version.
get_schema(subject, version) Get the schema of a subject version.
insert(subject, version[, schema_id, schema]) Insert a subject version into the cache.

Methods Documentation

get(subject, version)

Get the full set of schema and ID information for a subject version.

Parameters:
subject : str

The name of the subject.

version : int

The version number of the schema in the subject.

Returns:
schema_info : dict

A dictionary with the full set of information about the cached schema. The keys are:

"subject"

The name of the subject.

"version"

The version number of the schema in the subject.

"id"

ID of the schema in a Schema Registry.

"schema"

The Avro schema, preparsed by fastavro.parse_schema.

Raises:
ValueError

Raised if the schema does not exist in the cache.

See also

get_id, get_schema

get_id(subject, version)

Get the schema ID of a subject version.

Parameters:
subject : str

The name of the subject.

version : int

The version number of the schema in the subject.

Returns:
schema_id : int

ID of the schema in a Schema Registry.

Raises:
ValueError

Raised if the schema does not exist in the cache.

See also

get_schema, get

get_schema(subject, version)

Get the schema of a subject version.

Parameters:
subject : str

The name of the subject.

version : int

The version number of the schema in the subject.

Returns:
schema : dict

An Avro schema, preparsed by fastavro.parse_schema.

Raises:
ValueError

Raised if the schema does not exist in the cache.

See also

get_id, get

insert(subject, version, schema_id=None, schema=None)

Insert a subject version into the cache.

Parameters:
subject : str

The name of the subject.

version : int

The version number of the schema in the subject.

schema_id : int, optional

ID of the schema in a Schema Registry. See Notes.

schema : dict, optional

The Avro schema itself. See Notes.

Raises:
TypeError

Raised if the version parameter is a string. String-based versions, like “latest,” cannot be cached.

ValueError

Raised if the schema_id or schema parameters are needed but aren’t set. See Notes.

Notes

If the subject version being cached is already in the schema cache, then only one of schema_id or schema need to be passed to this method. However, if the schema isn’t cached, then both schema_id and schema need to be set. The schema_id and schema are added to the underlying schema cache.