Get an entry from a BibTeX file.

    .. note ::

        Returns the first matching entry.

    :param filename: The name of the BibTeX file.
    :param filter_function: A function returning ``True`` or ``False`` \
            whether the entry should be included or not.
    :param ignore_fields: An optional list of fields to strip from the BibTeX \
            file.

    :returns: A ``bibtexparser.BibDatabase`` object representing the \
            first matching entry. ``None`` if entry was not found.

def get_entry_by_filter(filename, filter_function, ignore_fields=None):
    """
    Get an entry from a BibTeX file.

    .. note ::

        Returns the first matching entry.

    :param filename: The name of the BibTeX file.
    :param filter_function: A function returning ``True`` or ``False`` \
            whether the entry should be included or not.
    :param ignore_fields: An optional list of fields to strip from the BibTeX \
            file.

    :returns: A ``bibtexparser.BibDatabase`` object representing the \
            first matching entry. ``None`` if entry was not found.
    """
    # Handle default argument
    if ignore_fields is None:
        ignore_fields = []

    # Open bibtex file
    with open(filename, 'r') as fh:
        bibtex = bibtexparser.load(fh)

    matching_entry = None
    try:
        # Try to fetch the matching entry dict
        for entry in bibtex.entries:
            if filter_function(entry):
                matching_entry = entry
    except KeyError:
        # If none found, return None
        return None

    if matching_entry is None:
        return None

    # Clean the entry dict if necessary
    matching_entry = {k: matching_entry[k]
                      for k in matching_entry if k not in ignore_fields}

    bib_db = bibtexparser.bibdatabase.BibDatabase()
    bib_db.entries = [matching_entry]
    return bib_db