Python SDK

Installation

$pip install multion
># or
>poetry add multion

Usage

Simply import MultiOn and start making calls to our API.

1from multion.client import MultiOn
2
3client = MultiOn(
4 api_key="YOUR_API_KEY" # defaults to os.getenv("MULTION_API_KEY")
5)
6response = client.browse(
7 url="https://google.com"
8)

Async Client

The SDK also exports an async client so that you can make non-blocking calls to our API.

1from multion.client import AsyncMultiOn
2
3client = AsyncMultiOn(
4 api_key="YOUR_API_KEY" # defaults to os.getenv("MULTION_API_KEY")
5)
6
7async def main() -> None:
8 await response = client.browse(
9 url="https://google.com"
10 )
11
12asyncio.run(main())

Exception Handling

All errors thrown by the SDK will be subclasses of ApiError.

1import multion
2
3try:
4 client.browse(...)
5except multion.core.ApiError as e: # handle all errors
6 print(e.status_code)
7 print(e.body)

Advanced

Retries

The MultiOn SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retriable and the number of retry attempts has not grown larger than the configured retry limit.

A request is deemed retriable when any of the following HTTP status codes is returned:

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

Use the max_retries request option to configure this behavior.

1from multion.client import MultiOn
2
3client = MultiOn()
4
5client.browse(url="https://google.com", {
6 max_retries=1 # override retries for a specific method
7})

Timeouts

By default, requests time out after 60 seconds. You can configure this with a timeout option at the client or request level.

1from multion.client import MultiOn
2
3client = MultiOn(
4 timeout=30.0, # all timeouts are 30 seconds
5)
6
7client.brwose(url="https://google.com", {
8 timeout_in_seconds=30.0 # override timeout for a specific method
9})

Custom HTTP client

You can override the httpx client to customize it for your use-case. Some common use-cases include support for proxies and transports.

1import httpx
2
3from multion.client import MultiOn
4
5client = MultiOn(
6 http_client=httpx.Client(
7 proxies="http://my.test.proxy.example.com",
8 transport=httpx.HTTPTransport(local_address="0.0.0.0"),
9 ),
10)