@classmethod
def from_file(cls, filename):
    """
        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
        """
    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)
