Skip to main content

Python library adapter for accessing Plaid APIs

Project description

Plaid Python Adapter

This is a python adapter library for accessing Plaid APIs.

Table of Contents

Environment:

Environment Configuration parameters for this library

Parameter Name Description
PLAID_CLIENT_ID Plaid Client Id
PLAID_PUBLIC_KEY Plaid Public Key
PLAID_SECRET Plaid Secret Key
PLAID_ENV Plaid Environment to work on. Sample values: 'sandbox','production','development'
PLAID_BASE_URL The base url of plaid to connect their API. E.G. https://sandbox.plaid.com

Steps to generate access token

Plaid requires the user to authenticate in order to use their APIs. So the steps for accessing the API are as below:

  1. Using your UI client, make a request to create_link_token which will return the link token.
  2. This link token will be sent to the UI for initializing Plaid. Once Plaid is initialized, we get the public token from plaid server.
  3. 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 token

Mandatory field:
client_user_id : Unique id to identify the client
Optional 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/#linktokencreate

2.exchange_public_token(public_token)

Use to exchange public token for an access token

Mandatory field:
public_token : public token received from plaid client

Response: For response, please refer to below link:
https://plaid.com/docs/api/tokens/#itempublic_tokenexchange

3.auth_request(access_token,account_ids)

Use to get account details associated with the access_token

Mandatory field:
access_token : Unique access token of the Plaid user
Optional 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/#authget

4.identity_request(access_token=None,account_ids)

Use to get identity details associated with the access_token

Mandatory field:
access_token : Unique access token of the Plaid user
Optional 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/#identityget

5.sync_bank_transfer_event(after_id,count)

Use to get bank transfer ACH details

Mandatory 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: 25
Minimum: 1
Maximum: 25

Response: For response, please refer to below link:
https://plaid.com/docs/api/products/#bank_transfereventsync

6.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 Plaid

Parameter name Type Default value Description
client_name string 'None' The name of Plaid Client
country_codes list ['US'] The country code of Plaid app.
language string 'en' The language of Plaid app
products list ['auth'] The products that are supported by Plaid app.
account_subtypes list ['checking', 'savings'] The account sub-types returned by Plaid app

Errors

The below list of errors are expected for the API's

Error name API Description
PlaidAdapterError ALL API's This is the base Error
PlaidAdapterConfigurationError initialize_plaid Raised when there is configuration error
PlaidCreateLinkTokenError create_link_token Raised when there is error while creating link token
PlaidExchangePublicTokenError exchange_public_token Raised when there is error while exchanging public token for an access token
PlaidAuthError auth_request Raised when there is error while fetching auth details
PlaidIdentityError identity_request Raised when there is error while fetching identity details
PlaidApiInternalServerError ALL API's Raised when there is an internal error returned by Plaid server
PlaidBankTransferSyncEventError sync_bank_transfer_event Raised when there is an error in fetching bank transfer events

Examples

from plaid_python_adapter.plaid_adapter import PlaidAdapter
from plaid_python_adapter.exceptions import *


def create_link_token():
    response_dict = {}
    plaid_adapter = PlaidAdapter()
    try:
        response = plaid_adapter.create_link_token(client_user_id='<Unique-Id>')
    except PlaidCreateLinkTokenError as err:
        #Handle the error
        pass
    except PlaidApiInternalServerError as err:
        #Handle the error
        pass
    response_dict = {
        'link_token': response.get('link_token'),
        'expiration': response.get('expiration'),
        'request_id': response.get('request_id')
    }
    return response_dict

def exchange_public_token(public_token):
    plaid_adapter = PlaidAdapter()
    try:
        response = plaid_adapter.exchange_public_token(public_token)
    except PlaidExchangePublicTokenError as err:
        #Handle the error
        pass
    except PlaidApiInternalServerError as err:
        #Handle the error
        pass
    access_token = response['access_token']
    return access_token

def auth_request(access_token=None, account_ids=None):
    accounts_details = {}
    plaid_adapter = PlaidAdapter()
    try:
        accounts_details = plaid_adapter.auth_request(access_token, account_ids)
    except PlaidAuthError as err:
        #Handle the error
        pass
    except PlaidApiInternalServerError as err:
        #Handle the error
        pass
    return accounts_details

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plaid-python-adapter-0.2.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

plaid_python_adapter-0.2-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file plaid-python-adapter-0.2.tar.gz.

File metadata

  • Download URL: plaid-python-adapter-0.2.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.20.0 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.5

File hashes

Hashes for plaid-python-adapter-0.2.tar.gz
Algorithm Hash digest
SHA256 0344bd412460bb2e70df5856b2cbe2471393c3c7c574287abd54191a04d692fe
MD5 c0257a6fcb057042413f04ef5ad80aef
BLAKE2b-256 de7283f67d4d78c691177fa9ed86e9601ff9727fd94f1d233598606b9def8a8e

See more details on using hashes here.

File details

Details for the file plaid_python_adapter-0.2-py3-none-any.whl.

File metadata

  • Download URL: plaid_python_adapter-0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.20.0 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.5

File hashes

Hashes for plaid_python_adapter-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2c669b8ae9598ca75a68691bc08f91e825b6262538153ce9ba4d495b620381ae
MD5 d4f69a52780027670cf0f9ccf9c8e69f
BLAKE2b-256 2687a05d85d53c1f158cbad51b59c988326f7b3b8c254fdd4382967d55ffaede

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page