Schema¶
- class lsst.alert.packet.Schema(schema_definition)¶
- Bases: - object- An Avro schema. - Parameters:
- schema_definitiondict
- An Avro schema definition as returned by e.g. - fastavro.schema.load_schema.
 
- schema_definition
 - Notes - The interaction with - fastavrohere needs some explanation.- When - fastavroloads a schema, it parses each of the types contained within that schema and remembers them for future use. So that if, for example, your schema defines a type- lsst.alert.diaSource,- fastavrowill remember that type and use it when referring to your schema.- However, it uses a single lookup table by type for these. Thus, if you load another schema which defines an - lsst.alert.diaSourcetype which is not the same as the first, then it will clobber the earlier definition, and confusion will reign.- We avoid this here by fully resolving everything (ie, all schemas are defined in terms of primitive types) and then clearing the - fastavrocache after loading.- Methods Summary - deserialize(record)- Deserialize an Avro packet folowing this schema. - from_file([filename])- Instantiate a - Schemaby reading its definition from the filesystem.- from_uri([base_uri])- Instantiate a - Schemaby reading its definition from a URI.- retrieve_alerts(fp)- Read alert packets from the given I/O stream. - serialize(record)- Create an Avro representation of data following this schema. - store_alerts(fp, records)- Store alert packets to the given I/O stream. - validate(record)- Validate packet contents against this schema. - Methods Documentation - deserialize(record)¶
- Deserialize an Avro packet folowing this schema. 
 - classmethod from_file(filename=None)¶
- Instantiate a - Schemaby reading its definition from the filesystem.
 - classmethod from_uri(base_uri: None | str | ResourcePath = None) Schema¶
- Instantiate a - Schemaby reading its definition from a URI.- Parameters:
- base_uristrorlsst.resources.ResourcePathorNone
- URI to the base schema as either a - ResourcePathor a string that can be converted to one. If- Nonethe most recent default schema will be used.
 
- base_uri
 
 - retrieve_alerts(fp)¶
- Read alert packets from the given I/O stream. - Parameters:
- fpderivative of IOBase
- I/O stream from which data will be read. 
- schemalist, optional
- A schema describing the contents of the Avro packets. If not provided, the schema used when writing the alert stream will be used. 
 
- fpderivative of 
- Returns:
- schemalsst.alert.Schema
- The schema with which alerts were written (which may be different from this schema being used for deserialization). 
- recordsiterable of dict
- Alert records. 
 
- schema
 
 - serialize(record)¶
- Create an Avro representation of data following this schema.