ImportError: cannot import name 'Client' from 'plaid'
I have been struggling to find an answer. I am trying to integrate plaid with my django project, however I continue to get the same error. I am on python 3.11 and plaid 19.0.0.
The plaid package in in my python site packages where it shows:
ImportError: cannot import name 'Client' from 'plaid' (/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/plaid/__init__.py)
And the init.py file is:
"""
The Plaid API
The Plaid REST API. Please see https://plaid.com/docs/api for more details. # noqa: E501
The version of the OpenAPI document: 2020-09-14_1.496.2
Generated by: https://openapi-generator.tech
"""
__version__ = "19.0.0"
# import ApiClient
from plaid.api_client import ApiClient
# import Configuration
from plaid.configuration import Configuration
# import Environments
from plaid.configuration import Environment
# import exceptions
from plaid.exceptions import OpenApiException
from plaid.exceptions import ApiAttributeError
from plaid.exceptions import ApiTypeError
from plaid.exceptions import ApiValueError
from plaid.exceptions import ApiKeyError
from plaid.exceptions import ApiException
Any help would be greatly appreciated
Following the documentation, it should look something like this:
from django.shortcuts import render
from plaid import ApiClient, Configuration
from plaid.api.plaid_api import PlaidApi
def plaid_link_view(request):
# Initialize Plaid client
configuration = Configuration(
host=PLAID_ENV,
api_key={
"clientId": PLAID_CLIENT_ID,
"secret": PLAID_SECRET,
},
)
api_client = ApiClient(configuration)
client = PlaidApi(api_client)
# Create Link token for user interaction
link_token_create_response = client.link_token_create(
user={
"client_user_id": request.user.id, # Replace with user identification method
},
products=["transactions"], # Adjust products based on your needs
)
link_token = link_token_create_response["link_token"]
# Render context with link_token for frontend integration
context = {
"link_token": link_token,
}
return render(request, "plaid_link.html", context)
You're probably following an outdated tutorial as the api was changed 3 years ago.