class_docstr: Restricts specified DHT keys to match a Pydantic schema.
  This allows to enforce types, min/max values, require a subkey to contain a public key, etc.
class_docstr_tok: ["Restricts","specified","DHT","keys","to","match","a","Pydantic","schema",".","This","allows","to","enforce","types",",","min\/max","values",",","require","a","subkey","to","contain","a","public","key",",","etc","."]
docstr: :param schema: The Pydantic model (a subclass of pydantic.BaseModel).
  
      You must always use strict types for the number fields
      (e.g. ``StrictInt`` instead of ``int``,
      ``confloat(strict=True, ge=0.0)`` instead of ``confloat(ge=0.0)``, etc.).
      See the validate() docstring for details.
  
      The model will be patched to adjust it for the schema validation.
  
  :param allow_extra_keys: Whether to allow keys that are not defined in the schema.
  
      If a SchemaValidator is merged with another SchemaValidator, this option applies to
      keys that are not defined in each of the schemas.
  
  :param prefix: (optional) Add ``prefix + '_'`` to the names of all schema fields.
docstr_tok: [":","param","schema",":","The","Pydantic","model","(","a","subclass","of","pydantic.BaseModel",")",".","You","must","always","use","strict","types","for","the","number","fields","(","e.g",".","``","StrictInt","``","instead","of","``","int","``",",","``","confloat","(","strict=True",",","ge=0.0",")","``","instead","of","``","confloat","(","ge=0.0",")","``",",","etc.",")",".","See","the","validate","(",")","docstring","for","details",".","The","model","will","be","patched","to","adjust","it","for","the","schema","validation",".",":","param","allow_extra_keys",":","Whether","to","allow","keys","that","are","not","defined","in","the","schema",".","If","a","SchemaValidator","is","merged","with","another","SchemaValidator",",","this","option","applies","to","keys","that","are","not","defined","in","each","of","the","schemas",".",":","param","prefix",":","(","optional",")","Add","``","prefix","+","'","_","'","``","to","the","names","of","all","schema","fields","."]
code: def __init__(
      self,
      schema: Type[pydantic.BaseModel],
      allow_extra_keys: bool = True,
      prefix: Optional[str] = None,
  ):
      """
      :param schema: The Pydantic model (a subclass of pydantic.BaseModel).
  
          You must always use strict types for the number fields
          (e.g. ``StrictInt`` instead of ``int``,
          ``confloat(strict=True, ge=0.0)`` instead of ``confloat(ge=0.0)``, etc.).
          See the validate() docstring for details.
  
          The model will be patched to adjust it for the schema validation.
  
      :param allow_extra_keys: Whether to allow keys that are not defined in the schema.
  
          If a SchemaValidator is merged with another SchemaValidator, this option applies to
          keys that are not defined in each of the schemas.
  
      :param prefix: (optional) Add ``prefix + '_'`` to the names of all schema fields.
      """
  
      self._patch_schema(schema)
      self._schemas = [schema]
  
      self._key_id_to_field_name = {}
      for field in schema.__fields__.values():
          raw_key = (
              f"{prefix}_{field.name}"
              if prefix is not None
              else field.name
          )
          self._key_id_to_field_name[
              DHTID.generate(source=raw_key).to_bytes()
          ] = field.name
      self._allow_extra_keys = allow_extra_keys
  
file_path: hivemind/hivemind/dht/schema.py
imports: import re
  from typing import Any, Dict, Optional, Type
  import pydantic
  from hivemind.dht.crypto import RSASignatureValidator
  from hivemind.dht.protocol import DHTProtocol
  from hivemind.dht.routing import DHTID
  from hivemind.dht.validation import DHTRecord, RecordValidatorBase
  from hivemind.utils import get_logger
label_desc: Use image node_id 1 to create a new SchemaValidator object from inherited base classes: RecordValidatorBase with example: obj = SchemaValidator(schema, allow_extra_keys, prefix)