code: def from_file(cls, filename):
          
          with open(filename) as infp:
              if filename.endswith('.yaml') or filename.endswith('.yml'):
                  import yaml
                  data = yaml.safe_load(infp)
              else:
                  import json
                  data = json.load(infp)
          return cls.from_data(data)
docs: Construct an APIDefinition by parsing the given `filename`.
  
          If PyYAML is installed, YAML files are supported.
          JSON files are always supported.
  
          :param filename: The filename to read.
          :rtype: APIDefinition