Client library for Plaid's legacy API.
Via pip:
pip install plaid-python-legacyVia source:
git clone git@github.com:plaid/plaid-python-legacy.gitpython setup.py installThe module supports all Plaid API endpoints. For complete information about the API, head to the docs.
fromplaidimportClientClient.config({
'url': 'https://tartan.plaid.com'
})By default, all non-200 responses will throw an error.
For more information on Plaid response codes, head to codes.
fromplaidimportClientfromplaidimporterrorsasplaid_errorsclient=Client(client_id='***', secret='***')
try:
response=client.connect('bofa', {
'username': '[something_invalid]',
'password': '***'
})
exceptplaid_errors.UnauthorizedError:
# handle thisIf you would prefer to handle non-20x status codes yourself, you can configure the client to suppress these exceptions
importjsonfromplaidimportClientClient.config({
'url': 'https://tartan.plaid.com',
'suppress_http_errors': True,
})
client=Client(client_id='***', secret='***')
response=client.connect('bofa', {
'username': '[something_invalid]',
'password': '***'
})
ifresponse.ok:
user=response.json()
else:
# handle non-20x status codesPublic endpoints (category information) require no authentication and can be accessed as follows:
fromplaidimportClientfromplaidimporterrorsasplaid_errorsfromplaid.utilsimportjsonclient=Client(client_id='***', secret='***')
categories=client.categories().json()Authenticated endpoints require a valid client_id and secret to access. You can use the sandbox client_id and secret for testing (test_id and test_secret) during development mode.
fromplaidimportClientfromplaidimporterrorsasplaid_errorsfromplaid.utilsimportjsonclient=Client(client_id='***', secret='***')
account_type='bofa'try:
response=client.connect(account_type, {
'username': '***',
'password': '***'
})
exceptplaid_errors.PlaidError:
passelse:
connect_data=response.json()fromplaidimportClientfromplaidimporterrorsasplaid_errorsfromplaid.utilsimportjsonclient=Client(client_id='***', secret='***')
account_type='bofa'try:
response=client.connect(account_type, {
'username': '***',
'password': '***'
})
exceptplaid_errors.PlaidError, e:
passelse:
ifresponse.status_code==200:
# User connecteddata=response.json()
elifresponse.stat_code==201:
# MFA requiredtry:
mfa_response=answer_mfa(response.json())
exceptplaid_errors.PlaidError, e:
passelse:
# check for 200 vs 201 responses# 201 indicates that additional MFA steps requireddefanswer_mfa(data):
ifdata['type'] =='questions':
# Ask your user for the answer to the question[s].# Although questions is a list, there is only ever a# single element in this list, at presentreturnanswer_question([q['question'] forqindata['mfa']])
elifdata['type'] =='list':
returnanswer_list(data['mfa'])
elifdata['type'] =='selection':
returnanswer_selections(data['mfa'])
else:
raiseException('Unknown mfa type from Plaid')
defanswer_question(questions):
# We have magically inferred the answer# so we respond immediately# In the real world, we would present questions[0]# to our user and submit their responseanswer='dogs'returnclient.connect_step(account_type, answer)
defanswer_list(devices):
# You should specify the device to which the passcode is sent.# The available devices are present in the devices listreturnclient.connect_step('bofa', None, options={
'send_method': {'type': 'phone'}
})
defanswer_selections(selections):
# We have magically inferred the answers# so we respond immediately# In the real world, we would present the selection# questions and choices to our user and submit their responses# in a JSON-encoded array with answers provided# in the same order as the given questionsanswer=json.dumps(['Yes', 'No'])
returnclient.connect_step(account_type, answer)Effectively the same as Connect.
client=Client(client_id='***', secret='***')
response=client.auth('bofa', {
'username': '***',
'password': '***'
})Effectively the same as Connect.
client=Client(client_id='***', secret='***')
response=client.auth('bofa', {
'username': '***',
'password': '***'
})
mfa_response=client.auth_step('bofa', 'my_answer')Add a product (auth or connect to the user)
client=Client(client_id='***', secret='***', access_token='usertoken')
response=client.upgrade('connect')client=Client(client_id='***', secret='***', access_token='usertoken')
client.connect_delete() ## deletes Connect user# ORclient.auth_delete() ## deletes Auth userExchange a public_token from Plaid Link for a Plaid access token and then
retrieve account data:
client=Client(client_id='***', secret='***')
response=client.exchange_token('test,chase,connected')
# client.access_token should now be populated with a# valid access_token; we can make authenticated requestsclient.auth('chase', {
'username': '***',
'password': '***'
})User previously Auth-ed
client=Client(client_id='***', secret='***', access_token='usertoken')
accounts=client.auth_get().json()User previously added
client=Client(client_id='***', secret='***', access_token='usertoken')
response=client.balance()User previously Connect-ed
client=Client(client_id='***', secret='***', access_token='usertoken')
response=client.connect_get()
transactions=response.json()User previously Info-ed
client=Client(client_id='***', secret='***', access_token='usertoken')
response=client.info_get()
info=response.json()User previously Income-ed
client=Client(client_id='***', secret='***', access_token='usertoken')
response=client.income_get()
income=response.json()User previously Risk-ed
client=Client(client_id='***', secret='***', access_token='usertoken')
response=client.risk_get()
risk=response.json()To search through or retrieve a list of all financial institutions supported by Plaid, use the /institutions/all/search and /institutions/all endpoints:
client=Client(client_id='***', secret='***')
# Search for an institution matching the name 'redwood credit' that supports ConnectinstitutionSearchResults=client.institution_all_search('redwood credit', 'connect'):
# Pull 200 institutions with, offseting 0 institutionsinstitutions=client.institutions_all(count=200, offset=0).json()
# Pull 50 institutions that support both Auth and Connectinstitutions=client.institutions_all(count=50, offset=0, products=["auth","connect"]).json()
# Pull a single institutionsingleInstitution=client.institution('ins_100003').json()For additional information, please see the API Institutions docs.
Note: Use of the institution_search() and institutions() methods has been deprecated. Use institution_all_search() and institutions_all() methods instead.
This repository was originally authored by Chris Forrette. Version 1.0.0 was authored by Ben Plesser.
Open an issue!
SSLError: EOF occurred in violation of protocol (_ssl.c:581)(plaid/plaid-python#62) - Work around is installingpyopenssl ndg-httpsclient pyasn1
All pull requests should be linted with flake8 and tested by running:
$ make test- @chrisforrette (Chris Forrette)
- @gae123