- Notifications
You must be signed in to change notification settings - Fork144
Python wrapper for the Intercom API.
intercom/python-intercom
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
The Intercom Python library provides convenient access to the Intercom APIs from Python.
pip install python-intercom
A full reference for this library is availablehere.
Instantiate and use the client with the following:
fromintercomimportIntercomclient=Intercom(token="YOUR_TOKEN",)client.ai_content.create_content_import_source(url="https://www.example.com",)
The SDK also exports anasync client so that you can make non-blocking calls to our API. Note that if you are constructing an Async httpx client class to pass into this client, usehttpx.AsyncClient() instead ofhttpx.Client() (e.g. for thehttpx_client parameter of this client).
importasynciofromintercomimportAsyncIntercomclient=AsyncIntercom(token="YOUR_TOKEN",)asyncdefmain()->None:awaitclient.ai_content.create_content_import_source(url="https://www.example.com", )asyncio.run(main())
When the API returns a non-success status code (4xx or 5xx response), a subclass of the following errorwill be thrown.
fromintercom.core.api_errorimportApiErrortry:client.ai_content.create_content_import_source(...)exceptApiErrorase:print(e.status_code)print(e.body)
Paginated requests will return aSyncPager orAsyncPager, which can be used as generators for the underlying object.
fromintercomimportIntercomclient=Intercom(token="YOUR_TOKEN",)response=client.articles.list()foriteminresponse:yielditem# alternatively, you can paginate page-by-pageforpageinresponse.iter_pages():yieldpage
# You can also iterate through pages and access the typed response per pagepager=client.articles.list(...)forpageinpager.iter_pages():print(page.response)# access the typed response for each pageforiteminpage:print(item)
The SDK provides access to raw response data, including headers, through the.with_raw_response property.The.with_raw_response property returns a "raw" client that can be used to access the.headers and.data attributes.
fromintercomimportIntercomclient=Intercom( ...,)response=client.ai_content.with_raw_response.create_content_import_source(...)print(response.headers)# access the response headersprint(response.data)# access the underlying objectpager=client.articles.list(...)print(pager.response)# access the typed response for the first pageforiteminpager:print(item)# access the underlying object(s)forpageinpager.iter_pages():print(page.response)# access the typed response for each pageforiteminpage:print(item)# access the underlying object(s)
The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as longas the request is deemed retryable and the number of retry attempts has not grown larger than the configuredretry limit (default: 2).
A request is deemed retryable when any of the following HTTP status codes is returned:
Use themax_retries request option to configure this behavior.
client.ai_content.create_content_import_source(...,request_options={"max_retries":1})
The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
fromintercomimportIntercomclient=Intercom( ...,timeout=20.0,)# Override timeout for a specific methodclient.ai_content.create_content_import_source(...,request_options={"timeout_in_seconds":1})
You can override thehttpx client to customize it for your use-case. Some common use-cases include support for proxiesand transports.
importhttpxfromintercomimportIntercomclient=Intercom( ...,httpx_client=httpx.Client(proxy="http://my.test.proxy.example.com",transport=httpx.HTTPTransport(local_address="0.0.0.0"), ),)
While we value open-source contributions to this SDK, this library is generated programmatically.Additions made directly to this library would have to be moved over to our generation code,otherwise they would be overwritten upon the next generated release. Feel free to open a PR asa proof of concept, but know that we will not be able to merge it as-is. We suggest openingan issue first to discuss with us!
On the other hand, contributions to the README are always very welcome!
About
Python wrapper for the Intercom API.
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.