Python SDK

Installation

pip install multion
# or
poetry add multion

Usage

Simply import MultiOn and start making calls to our API.

from multion.client import MultiOn
client = MultiOn(
api_key="YOUR_API_KEY" # defaults to os.getenv("MULTION_API_KEY")
)
response = client.browse(
url="https://google.com"
)

Async Client

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

from multion.client import AsyncMultiOn
client = AsyncMultiOn(
api_key="YOUR_API_KEY" # defaults to os.getenv("MULTION_API_KEY")
)
async def main() -> None:
await response = client.browse(
url="https://google.com"
)
asyncio.run(main())

Exception Handling

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

import multion
try:
client.browse(...)
except multion.core.ApiError as e: # handle all errors
print(e.status_code)
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.

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

Timeouts

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

from multion.client import MultiOn
client = MultiOn(
timeout=30.0, # all timeouts are 30 seconds
)
client.brwose(url="https://google.com", {
timeout_in_seconds=30.0 # override timeout for a specific method
})

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.

import httpx
from multion.client import MultiOn
client = MultiOn(
http_client=httpx.Client(
proxies="http://my.test.proxy.example.com",
transport=httpx.HTTPTransport(local_address="0.0.0.0"),
),
)