Package: plaid-python-adapter
Plaid Python AdapterThis is a python adapter library for accessing Plaid APIs.Table of ContentsEnvironment1. Create Link Token2. Exchange Public Token3. Auth Request4. Identity Request5. Sync Bank Transfer Event6. Initialize PlaidErrorsEnvironment:Environment Configuration parameters for this libraryParameter NameDescriptionPLAID_CLIENT_IDPlaid Client IdPLAID_PUBLIC_KEYPlaid Public KeyPLAID_SECRETPlaid Secret KeyPLAID_ENVPlaid Environment to work on. Sample values: 'sandbox','production','development'PLAID_BASE_URLThe base url of plaid to connect their API. E.G.https://sandbox.plaid.comSteps to generate access tokenPlaid requires the user to authenticate in order to use their APIs.
So the steps for accessing the API are as below:Using your UI client, make a request to create_link_token which will return the link token.This link token will be sent to the UI for initializing Plaid. Once Plaid is initialized, we get the public token from plaid server.Then using the public token you need to make a request to exchange_public_token to get the access token. This access token is used for all the remaining api calls.1.create_link_token(client_user_id,access_token)Use to get the plaid link tokenMandatory field:client_user_id: Unique id to identify the clientOptional Field:access_token: If link token need to be re-initialized with the existing access token.Response: For response, please refer to below link:https://plaid.com/docs/api/tokens/#linktokencreate2.exchange_public_token(public_token)Use to exchange public token for an access tokenMandatory field:public_token: public token received from plaid clientResponse: For response, please refer to below link:https://plaid.com/docs/api/tokens/#itempublic_tokenexchange3.auth_request(access_token,account_ids)Use to get account details associated with the access_tokenMandatory field:access_token: Unique access token of the Plaid userOptional Field:account_ids: List of account ids for which details needs to be fetched.Response: For response, please refer to below link:https://plaid.com/docs/api/products/#authget4.identity_request(access_token=None,account_ids)Use to get identity details associated with the access_tokenMandatory field:access_token: Unique access token of the Plaid userOptional Field:account_ids: List of account ids for which details needs to be fetched.Response: For response, please refer to below link:https://plaid.com/docs/api/products/#identityget5.sync_bank_transfer_event(after_id,count)Use to get bank transfer ACH detailsMandatory field:after_id: The latest (largest) event_id fetched via the sync endpoint, or 0 initially.Optional Field:count: The maximum number of bank transfer events to return.Default: 25Minimum: 1Maximum: 25Response: For response, please refer to below link:https://plaid.com/docs/api/products/#bank_transfereventsync6.initialize_plaid(client_name,country_codes,language, products, account_subtypes)Use to initialize plaid client for specific configuration. All the parameters are optional with the below default values.Optional Field:Intialization Parameters for PlaidParameter nameTypeDefault valueDescriptionclient_namestring'None'The name of Plaid Clientcountry_codeslist['US']The country code of Plaid app.languagestring'en'The language of Plaid appproductslist['auth']The products that are supported by Plaid app.account_subtypeslist['checking', 'savings']The account sub-types returned by Plaid appErrorsThe below list of errors are expected for the API'sError nameAPIDescriptionPlaidAdapterErrorALL API'sThis is the base ErrorPlaidAdapterConfigurationErrorinitialize_plaidRaised when there is configuration errorPlaidCreateLinkTokenErrorcreate_link_tokenRaised when there is error while creating link tokenPlaidExchangePublicTokenErrorexchange_public_tokenRaised when there is error while exchanging public  token for an access tokenPlaidAuthErrorauth_requestRaised when there is error while fetching auth detailsPlaidIdentityErroridentity_requestRaised when there is error while fetching identity detailsPlaidApiInternalServerErrorALL API'sRaised when there is an internal error returned by Plaid serverPlaidBankTransferSyncEventErrorsync_bank_transfer_eventRaised when there is an error in fetching bank transfer eventsExamplesfromplaid_python_adapter.plaid_adapterimportPlaidAdapterfromplaid_python_adapter.exceptionsimport*defcreate_link_token():response_dict={}plaid_adapter=PlaidAdapter()try:response=plaid_adapter.create_link_token(client_user_id='<Unique-Id>')exceptPlaidCreateLinkTokenErroraserr:#Handle the errorpassexceptPlaidApiInternalServerErroraserr:#Handle the errorpassresponse_dict={'link_token':response.get('link_token'),'expiration':response.get('expiration'),'request_id':response.get('request_id')}returnresponse_dictdefexchange_public_token(public_token):plaid_adapter=PlaidAdapter()try:response=plaid_adapter.exchange_public_token(public_token)exceptPlaidExchangePublicTokenErroraserr:#Handle the errorpassexceptPlaidApiInternalServerErroraserr:#Handle the errorpassaccess_token=response['access_token']returnaccess_tokendefauth_request(access_token=None,account_ids=None):accounts_details={}plaid_adapter=PlaidAdapter()try:accounts_details=plaid_adapter.auth_request(access_token,account_ids)exceptPlaidAuthErroraserr:#Handle the errorpassexceptPlaidApiInternalServerErroraserr:#Handle the errorpassreturnaccounts_details