def is_valid(bson):
 if (not isinstance(bson, bytes)):
  raise TypeError('BSON data must be an instance of a subclass of bytes')
 try:
  _bson_to_dict(bson, DEFAULT_CODEC_OPTIONS)
  return True
 except Exception:
  return False

def is_valid ( bson ) : if ( not isinstance ( bson , bytes ) ) : raise TypeError ( 'BSON data must be an instance of a subclass of bytes' ) try : _bson_to_dict ( bson , DEFAULT_CODEC_OPTIONS ) return True except Exception : return False
check that the given string represents valid :class:bson data .