SubjectCache#
- class kafkit.registry.sansio.SubjectCache(schema_cache)#
Bases:
objectA 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. If version is given as a string (
"latest"), a ValueError is raised.
- Returns:
schema_info – 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 <fastavro._schema_py.parse_schema>.
- Return type:
dict
- Raises:
ValueError – Raised if the schema does not exist in the cache.
See also
- 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 – ID of the schema in a Schema Registry.
- Return type:
int
- Raises:
ValueError – Raised if the schema does not exist in the cache.
See also
- 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 – An Avro schema, preparsed by fastavro.parse_schema <fastavro._schema_py.parse_schema>.
- Return type:
dict
- Raises:
ValueError – Raised if the schema does not exist in the cache.
- insert(subject, version, schema_id=None, schema=None)#
Insert a subject version into the cache.
If the subject version being cached is already in the schema cache, then only one of
schema_idorschemaneed to be passed to this method. However, if the schema isn’t cached, then bothschema_idandschemaneed to be set. Theschema_idandschemaare added to the underlying schema 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.
schema (dict, optional) – The Avro schema itself.
- Raises:
TypeError – Raised if the
versionparameter is a string. String-based versions, like “latest,” cannot be cached.ValueError – Raised if the
schema_idorschemaparameters are needed but aren’t set.
- Return type: