Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Python wrapper for the Intercom API.

NotificationsYou must be signed in to change notification settings

intercom/python-intercom

Repository files navigation

fern shieldpypi

The Intercom Python library provides convenient access to the Intercom APIs from Python.

Table of Contents

Installation

pip install python-intercom

Reference

A full reference for this library is availablehere.

Usage

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",)

Async Client

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())

Exception Handling

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)

Pagination

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)

Advanced

Access Raw Response Data

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)

Retries

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:

  • 408 (Timeout)
  • 429 (Too Many Requests)
  • 5XX (Internal Server Errors)

Use themax_retries request option to configure this behavior.

client.ai_content.create_content_import_source(...,request_options={"max_retries":1})

Timeouts

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})

Custom Client

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"),    ),)

Contributing

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!


[8]ページ先頭

©2009-2025 Movatter.jp