Intercom Python SDK
The Python Intercom SDK (PyPI project name `python-intercom`, installs `intercom_python_sdk`) provides a convenient way to interact with the Intercom API. It allows developers to manage users, conversations, events, and more. The SDK is currently at version 5.0.1 and is regularly updated through automated API specification regenerations.
Common errors
-
ModuleNotFoundError: No module named 'intercom_python_sdk'
cause The package was installed using an incorrect name (e.g., `pip install intercom_python_sdk`) or not installed at all, preventing the correct module from being found.fixEnsure you install the package using `pip install python-intercom`. The installed package name is `intercom_python_sdk`, which is what you should import. -
TypeError: IntercomClient.__init__() got an unexpected keyword argument 'api_key'
cause Attempting to initialize the Intercom client using `api_key`, which was a parameter in older versions (pre-v4). The current client expects `personal_access_token`.fixInitialize the client with `personal_access_token=os.environ.get('INTERCOM_ACCESS_TOKEN')` or `personal_access_token='YOUR_TOKEN'`. -
AttributeError: 'IntercomClient' object has no attribute 'users'
cause This error often occurs when migrating from older SDK versions (pre-v4) to the newer v4/v5 client, or if the client object is not correctly initialized. The way resources are accessed changed in the Fern-generated SDK.fixEnsure you are using the correct client initialization and resource access patterns for v4/v5. For example, `client.users.list_all()` is the correct way to access user-related methods.
Warnings
- gotcha The PyPI project name is `python-intercom`, but the actual Python package/module name you import is `intercom_python_sdk`. Attempting to `pip install intercom_python_sdk` or `pip install python_intercom` will fail.
- breaking Version 4.0.0 introduced a complete rewrite of the SDK using Fern, leading to significant breaking changes in client initialization, class names, method signatures, and return types. Code written for v3 is incompatible with v4/v5.
- gotcha The client requires a `personal_access_token` for authentication. Direct inclusion in code is discouraged.
Install
-
pip install python-intercom
Imports
- IntercomClient
from python_intercom import IntercomClient
from intercom_python_sdk import IntercomClient
Quickstart
import os
from intercom_python_sdk import IntercomClient
# Initialize the client with your Personal Access Token
# Recommended: Store token in an environment variable named INTERCOM_ACCESS_TOKEN
client = IntercomClient(personal_access_token=os.environ.get("INTERCOM_ACCESS_TOKEN", ""))
if not client.personal_access_token:
print("Error: INTERCOM_ACCESS_TOKEN environment variable not set.")
print("Please set it or pass your token directly to IntercomClient(personal_access_token='YOUR_TOKEN')")
else:
try:
# Example: List all users
users_list = client.users.list_all(per_page=1)
if users_list and users_list.data:
print(f"Successfully retrieved {len(users_list.data)} user(s).")
for user in users_list.data:
print(f" User ID: {user.id}, Email: {user.email}")
else:
print("No users found or an empty list was returned.")
except Exception as e:
print(f"An error occurred: {e}")