Filters

Filters are used to search lending club for loans to invest in. There are many filters you can use, here are some examples with the main Filter class.

For example, to search for B grade loans, you could create a filter like this:

>>> filters = Filter()
>>> filters['grades']['B'] = True

Or, another more complex example:

>>> filters = Filter()
>>> filters['grades']['B'] = True
>>> filters['funding_progress'] = 90
>>> filters['term']['Year5'] = False

This would search for B grade loans that are at least 90% funded and not 5 year loans.

Filters currently do not support all search criteria. To see what is supported, create one and print it:

>>> filter = Filter()
>>> print filter
{'exclude_existing': True,
 'funding_progress': 0,
 'grades': {'A': False,
            'All': True,
            'B': False,
            'C': False,
            'D': False,
            'E': False,
            'F': False,
            'G': False},
 'term': {'Year3': True,
          'Year5': True}}

You can also set the values on instantiation:

>>> filters = Filter({'grades': {'B': True, 'C': True, 'D': True, 'E': True}})

Filter

class lendingclub.filters.Filter(filters=None)

Bases: dict

The default search filter that let’s you refine your search based on a dictionary of search facets. Not all search options are supported yet.

Parameters:

filters : dict, optional

This will override any of the search filters you want on instantiation.

Examples

See the default filters:

>>> from lendingclub.filters import Filter
>>> from pprint import pprint
>>> filter = Filter()
>>> pprint(filter)
{'exclude_existing': True,
 'funding_progress': 0,
 'grades': {'A': False,
            'All': True,
            'B': False,
            'C': False,
            'D': False,
            'E': False,
            'F': False,
            'G': False},
 'term': {'Year3': True,
          'Year5': True}}

Set filters on instantiation:

>>> from lendingclub.filters import Filter
>>> from pprint import pprint
>>> filters = Filter({'grades': {'B': True, 'C': True, 'D': True, 'E': True}})
>>> pprint(filters['grades'])
{'All': False,
 'A': False,
 'B': True,
 'C': True,
 'D': True,
 'E': True,
 'F': False,
 'G': False}

Methods

search_string()

” Returns the JSON string that LendingClub expects for it’s search

validate(results)

Validate that the results indeed match the filters. It’s a VERY good idea to run your search results through this, even though the filters were passed to LendingClub in your search. Since we’re not using formal APIs for LendingClub, they could change the way their search works at anytime, which might break the filters.

Parameters:

results : list

A list of loan note records returned from LendingClub

Returns:

boolean

True or raises FilterValidationError

Raises:

FilterValidationError

If a loan does not match the filter criteria

validate_one(loan)

Validate a single loan result record against the filters

Parameters:

loan : dict

A single loan note record

Returns:

boolean

True or raises FilterValidationError

Raises:

FilterValidationError

If the loan does not match the filter criteria

FilterByLoanID

class lendingclub.filters.FilterByLoanID(loan_id)

Bases: lendingclub.filters.Filter

Creates a filter to search by loan ID. You can either search by 1 loan ID or for multiple loans by ID.

Parameters:

loan_id : int or list

The loan ID or a list of loan IDs

Examples

Search for 1 loan by ID:

>>> from lendingclub import LendingClub
>>> from lendingclub.filters import FilterByLoanID
>>> lc = LendingClub(email='test@test.com', password='secret123')
>>> lc.authenticate()
True
>>> filter = FilterByLoanID(1234)  # Search for the loan 1234
>>> results = lc.search(filter)
>>> len(results['loans'])
1

Search for multiple loans by ID:

>>> from lendingclub import LendingClub
>>> from lendingclub.filters import FilterByLoanID
>>> lc = LendingClub(email='test@test.com', password='secret123')
>>> lc.authenticate()
True
>>> filter = FilterByLoanID(54321, 76432)  # Search for two loans: 54321 and 76432
>>> results = lc.search(filter)
>>> len(results['loans'])
2

Methods

SavedFilter

class lendingclub.filters.SavedFilter(lc, filter_id)

Bases: lendingclub.filters.Filter

Load a saved search filter from the site. Since this is loading a filter from the server, the individual values cannot be modified. Most often it is easiest to load the saved filters from LendingClub, via get_saved_filters and get_saved_filter. See examples.

Parameters:

lc : lendingclub.LendingClub

An instance of the LendingClub class that will be used to communicate with the site

filter_id : int

The ID of the filter to load

Examples

The SavedFilter needs to use an instance of LendingClub to access the site, so the class has a couple wrappers you can use to load SavedFilters. Here are a couple examples of loading saved filters from the LendingClub instance.

Load all saved filters:
>>> from lendingclub import LendingClub
>>> from lendingclub.filters import SavedFilter
>>> lc = LendingClub(email='test@test.com', password='secret123')
>>> lc.authenticate()
True
>>> filters = SavedFilter.all_filters(lc)    # Get a list of all saved filters on LendinClub.com
>>> print filters
[<SavedFilter: 12345, '90 Percent'>, <SavedFilter: 23456, 'Only A loans'>]
Load a single saved filter:
>>> from lendingclub import LendingClub
>>> from lendingclub.filters import SavedFilter
>>> lc = LendingClub(email='test@test.com', password='secret123')
>>> lc.authenticate()
True
>>> filter = lc.get_saved_filter(23456)    # Get a single saved search filter from the site by ID
>>> filter.name
u'Only A'

Attributes

id  
json  
json_text  
lc  
name  
response  

Methods

static all_filters(lc)

Get a list of all your saved filters

Parameters:

lc : lendingclub.LendingClub

An instance of the authenticated LendingClub class

Returns:

list

A list of lendingclub.filters.SavedFilter objects

load()

Load the filter from the server

reload()

Reload the saved filter

search_string()

Get the search JSON string to send to the server

Exceptions

exception lendingclub.filters.FilterValidationError(value=None, loan=None, criteria=None)

Bases: exceptions.Exception

A loan note does not match the filters set.

After a search is performed, each loan returned from the server will be validate against the filter’s criteria, for good measure. If it doesn’t match, this exception is thrown.

Parameters:

value : string

The error message

loan : dict

The loan that did not match

criteria : string

The filter item that the loan failed on.

exception lendingclub.filters.SavedFilterError(value, request=None)

Bases: exceptions.Exception

An error occurred while loading or processing a :class:SavedFilter

Parameters:

value : string

The error message

response : requests.Response

The Response object from the HTTP request to find the saved filter.