# ApifyClient<!-- -->

Synchronous client for the Apify API.

This is the main entry point for interacting with the Apify platform. It provides methods to access resource-specific sub-clients for managing Actors, runs, datasets, key-value stores, request queues, schedules, webhooks, and more.

The client automatically handles retries with exponential backoff for failed or rate-limited requests.

### Usage

```
from apify_client import ApifyClient



client = ApifyClient(token='MY-APIFY-TOKEN')



# Start an Actor and wait for it to finish.

actor_client = client.actor('apify/python-example')

run = actor_client.call(run_input={'first_number': 1, 'second_number': 2})



# Fetch results from the run's default dataset.

if run is not None:

    dataset_client = client.dataset(run.default_dataset_id)

    items = dataset_client.list_items().items

    for item in items:

        print(item)
```

## Index[**](#Index)

### Methods

* [**\_\_init\_\_](https://docs.apify.com/api/client/python/api/client/python/reference/class/ApifyClient.md#__init__)
* [**actor](https://docs.apify.com/api/client/python/api/client/python/reference/class/ApifyClient.md#actor)
* [**actors](https://docs.apify.com/api/client/python/api/client/python/reference/class/ApifyClient.md#actors)
* [**build](https://docs.apify.com/api/client/python/api/client/python/reference/class/ApifyClient.md#build)
* [**builds](https://docs.apify.com/api/client/python/api/client/python/reference/class/ApifyClient.md#builds)
* [**dataset](https://docs.apify.com/api/client/python/api/client/python/reference/class/ApifyClient.md#dataset)
* [**datasets](https://docs.apify.com/api/client/python/api/client/python/reference/class/ApifyClient.md#datasets)
* [**key\_value\_store](https://docs.apify.com/api/client/python/api/client/python/reference/class/ApifyClient.md#key_value_store)
* [**key\_value\_stores](https://docs.apify.com/api/client/python/api/client/python/reference/class/ApifyClient.md#key_value_stores)
* [**log](https://docs.apify.com/api/client/python/api/client/python/reference/class/ApifyClient.md#log)
* [**request\_queue](https://docs.apify.com/api/client/python/api/client/python/reference/class/ApifyClient.md#request_queue)
* [**request\_queues](https://docs.apify.com/api/client/python/api/client/python/reference/class/ApifyClient.md#request_queues)
* [**run](https://docs.apify.com/api/client/python/api/client/python/reference/class/ApifyClient.md#run)
* [**runs](https://docs.apify.com/api/client/python/api/client/python/reference/class/ApifyClient.md#runs)
* [**schedule](https://docs.apify.com/api/client/python/api/client/python/reference/class/ApifyClient.md#schedule)
* [**schedules](https://docs.apify.com/api/client/python/api/client/python/reference/class/ApifyClient.md#schedules)
* [**store](https://docs.apify.com/api/client/python/api/client/python/reference/class/ApifyClient.md#store)
* [**task](https://docs.apify.com/api/client/python/api/client/python/reference/class/ApifyClient.md#task)
* [**tasks](https://docs.apify.com/api/client/python/api/client/python/reference/class/ApifyClient.md#tasks)
* [**user](https://docs.apify.com/api/client/python/api/client/python/reference/class/ApifyClient.md#user)
* [**webhook](https://docs.apify.com/api/client/python/api/client/python/reference/class/ApifyClient.md#webhook)
* [**webhook\_dispatch](https://docs.apify.com/api/client/python/api/client/python/reference/class/ApifyClient.md#webhook_dispatch)
* [**webhook\_dispatches](https://docs.apify.com/api/client/python/api/client/python/reference/class/ApifyClient.md#webhook_dispatches)
* [**webhooks](https://docs.apify.com/api/client/python/api/client/python/reference/class/ApifyClient.md#webhooks)
* [**with\_custom\_http\_client](https://docs.apify.com/api/client/python/api/client/python/reference/class/ApifyClient.md#with_custom_http_client)

### Properties

* [**http\_client](https://docs.apify.com/api/client/python/api/client/python/reference/class/ApifyClient.md#http_client)
* [**token](https://docs.apify.com/api/client/python/api/client/python/reference/class/ApifyClient.md#token)

## Methods<!-- -->[**](#Methods)

### [**](#__init__)\_\_init\_\_

* ****\_\_init\_\_**(token, \*, api\_url, api\_public\_url, max\_retries, min\_delay\_between\_retries, timeout\_short, timeout\_medium, timeout\_long, timeout\_max, headers): None

- Initialize the Apify API client.

  To use a custom HTTP client, use the `with_custom_http_client` class method instead.

  ***

  #### Parameters

  * ##### optionaltoken: str | None = <!-- -->None

    The Apify API token. You can find your token on the [Integrations](https://console.apify.com/account/integrations) page in the Apify Console.

  * ##### optionalkeyword-onlyapi\_url: str = <!-- -->DEFAULT\_API\_URL

    The URL of the Apify API server to connect to. Defaults to <https://api.apify.com>. It can be an internal URL that is not globally accessible, in which case `api_public_url` should be set as well.

  * ##### optionalkeyword-onlyapi\_public\_url: str | None = <!-- -->DEFAULT\_API\_URL

    The globally accessible URL of the Apify API server. Should be set only if `api_url` is an internal URL that is not globally accessible. Defaults to <https://api.apify.com>.

  * ##### optionalkeyword-onlymax\_retries: int = <!-- -->DEFAULT\_MAX\_RETRIES

    How many times to retry a failed request at most.

  * ##### optionalkeyword-onlymin\_delay\_between\_retries: timedelta = <!-- -->DEFAULT\_MIN\_DELAY\_BETWEEN\_RETRIES

    How long will the client wait between retrying requests (increases exponentially from this value).

  * ##### optionalkeyword-onlytimeout\_short: timedelta = <!-- -->DEFAULT\_TIMEOUT\_SHORT

    Default timeout for short-duration API operations (simple CRUD operations, ...).

  * ##### optionalkeyword-onlytimeout\_medium: timedelta = <!-- -->DEFAULT\_TIMEOUT\_MEDIUM

    Default timeout for medium-duration API operations (batch operations, listing, ...).

  * ##### optionalkeyword-onlytimeout\_long: timedelta = <!-- -->DEFAULT\_TIMEOUT\_LONG

    Default timeout for long-duration API operations (long-polling, streaming, ...).

  * ##### optionalkeyword-onlytimeout\_max: timedelta = <!-- -->DEFAULT\_TIMEOUT\_MAX

    Maximum timeout cap for exponential timeout growth across retries.

  * ##### optionalkeyword-onlyheaders: dict\[str, str] | None = <!-- -->None

    Additional HTTP headers to include in all API requests.

  #### Returns None

### [**](#actor)actor

* ****actor**(actor\_id): [ActorClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/ActorClient.md)

- Get the sub-client for a specific Actor.

  ***

  #### Parameters

  * ##### actor\_id: str

    ID of the Actor to be manipulated.

  #### Returns [ActorClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/ActorClient.md)

### [**](#actors)actors

* ****actors**(): [ActorCollectionClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/ActorCollectionClient.md)

- Get the sub-client for the Actor collection, allowing to list and create Actors.

  ***

  #### Returns [ActorCollectionClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/ActorCollectionClient.md)

### [**](#build)build

* ****build**(build\_id): [BuildClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/BuildClient.md)

- Get the sub-client for a specific Actor build.

  ***

  #### Parameters

  * ##### build\_id: str

    ID of the Actor build to be manipulated.

  #### Returns [BuildClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/BuildClient.md)

### [**](#builds)builds

* ****builds**(): [BuildCollectionClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/BuildCollectionClient.md)

- Get the sub-client for the build collection, allowing to list builds.

  ***

  #### Returns [BuildCollectionClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/BuildCollectionClient.md)

### [**](#dataset)dataset

* ****dataset**(dataset\_id): [DatasetClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/DatasetClient.md)

- Get the sub-client for a specific dataset.

  ***

  #### Parameters

  * ##### dataset\_id: str

    ID of the dataset to be manipulated.

  #### Returns [DatasetClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/DatasetClient.md)

### [**](#datasets)datasets

* ****datasets**(): [DatasetCollectionClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/DatasetCollectionClient.md)

- Get the sub-client for the dataset collection, allowing to list and create datasets.

  ***

  #### Returns [DatasetCollectionClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/DatasetCollectionClient.md)

### [**](#key_value_store)key\_value\_store

* ****key\_value\_store**(key\_value\_store\_id): [KeyValueStoreClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/KeyValueStoreClient.md)

- Get the sub-client for a specific key-value store.

  ***

  #### Parameters

  * ##### key\_value\_store\_id: str

    ID of the key-value store to be manipulated.

  #### Returns [KeyValueStoreClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/KeyValueStoreClient.md)

### [**](#key_value_stores)key\_value\_stores

* ****key\_value\_stores**(): [KeyValueStoreCollectionClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/KeyValueStoreCollectionClient.md)

- Get the sub-client for the key-value store collection, allowing to list and create key-value stores.

  ***

  #### Returns [KeyValueStoreCollectionClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/KeyValueStoreCollectionClient.md)

### [**](#log)log

* ****log**(build\_or\_run\_id): [LogClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/LogClient.md)

- Get the sub-client for retrieving logs of an Actor build or run.

  ***

  #### Parameters

  * ##### build\_or\_run\_id: str

    ID of the Actor build or run for which to access the log.

  #### Returns [LogClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/LogClient.md)

### [**](#request_queue)request\_queue

* ****request\_queue**(request\_queue\_id, \*, client\_key): [RequestQueueClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/RequestQueueClient.md)

- Get the sub-client for a specific request queue.

  ***

  #### Parameters

  * ##### request\_queue\_id: str

    ID of the request queue to be manipulated.

  * ##### optionalkeyword-onlyclient\_key: str | None = <!-- -->None

    A unique identifier of the client accessing the request queue.

  #### Returns [RequestQueueClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/RequestQueueClient.md)

### [**](#request_queues)request\_queues

* ****request\_queues**(): [RequestQueueCollectionClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/RequestQueueCollectionClient.md)

- Get the sub-client for the request queue collection, allowing to list and create request queues.

  ***

  #### Returns [RequestQueueCollectionClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/RequestQueueCollectionClient.md)

### [**](#run)run

* ****run**(run\_id): [RunClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/RunClient.md)

- Get the sub-client for a specific Actor run.

  ***

  #### Parameters

  * ##### run\_id: str

    ID of the Actor run to be manipulated.

  #### Returns [RunClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/RunClient.md)

### [**](#runs)runs

* ****runs**(): [RunCollectionClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/RunCollectionClient.md)

- Get the sub-client for the run collection, allowing to list Actor runs.

  ***

  #### Returns [RunCollectionClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/RunCollectionClient.md)

### [**](#schedule)schedule

* ****schedule**(schedule\_id): [ScheduleClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/ScheduleClient.md)

- Get the sub-client for a specific schedule.

  ***

  #### Parameters

  * ##### schedule\_id: str

    ID of the schedule to be manipulated.

  #### Returns [ScheduleClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/ScheduleClient.md)

### [**](#schedules)schedules

* ****schedules**(): [ScheduleCollectionClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/ScheduleCollectionClient.md)

- Get the sub-client for the schedule collection, allowing to list and create schedules.

  ***

  #### Returns [ScheduleCollectionClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/ScheduleCollectionClient.md)

### [**](#store)store

* ****store**(): [StoreCollectionClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/StoreCollectionClient.md)

- Get the sub-client for the Apify Store, allowing to list Actors published in the store.

  ***

  #### Returns [StoreCollectionClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/StoreCollectionClient.md)

### [**](#task)task

* ****task**(task\_id): [TaskClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/TaskClient.md)

- Get the sub-client for a specific Actor task.

  ***

  #### Parameters

  * ##### task\_id: str

    ID of the task to be manipulated.

  #### Returns [TaskClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/TaskClient.md)

### [**](#tasks)tasks

* ****tasks**(): [TaskCollectionClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/TaskCollectionClient.md)

- Get the sub-client for the task collection, allowing to list and create Actor tasks.

  ***

  #### Returns [TaskCollectionClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/TaskCollectionClient.md)

### [**](#user)user

* ****user**(user\_id): [UserClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/UserClient.md)

- Get the sub-client for querying user data.

  ***

  #### Parameters

  * ##### optionaluser\_id: str | None = <!-- -->None

    ID of user to be queried. If None, queries the user belonging to the token supplied to the client.

  #### Returns [UserClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/UserClient.md)

### [**](#webhook)webhook

* ****webhook**(webhook\_id): [WebhookClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/WebhookClient.md)

- Get the sub-client for a specific webhook.

  ***

  #### Parameters

  * ##### webhook\_id: str

    ID of the webhook to be manipulated.

  #### Returns [WebhookClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/WebhookClient.md)

### [**](#webhook_dispatch)webhook\_dispatch

* ****webhook\_dispatch**(webhook\_dispatch\_id): [WebhookDispatchClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/WebhookDispatchClient.md)

- Get the sub-client for a specific webhook dispatch.

  ***

  #### Parameters

  * ##### webhook\_dispatch\_id: str

    ID of the webhook dispatch to access.

  #### Returns [WebhookDispatchClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/WebhookDispatchClient.md)

### [**](#webhook_dispatches)webhook\_dispatches

* ****webhook\_dispatches**(): [WebhookDispatchCollectionClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/WebhookDispatchCollectionClient.md)

- Get the sub-client for the webhook dispatch collection, allowing to list webhook dispatches.

  ***

  #### Returns [WebhookDispatchCollectionClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/WebhookDispatchCollectionClient.md)

### [**](#webhooks)webhooks

* ****webhooks**(): [WebhookCollectionClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/WebhookCollectionClient.md)

- Get the sub-client for the webhook collection, allowing to list and create webhooks.

  ***

  #### Returns [WebhookCollectionClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/WebhookCollectionClient.md)

### [**](#with_custom_http_client)with\_custom\_http\_client

* ****with\_custom\_http\_client**(token, \*, api\_url, api\_public\_url, http\_client): [ApifyClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/ApifyClient.md)

- Create an `ApifyClient` instance with a custom HTTP client.

  Use this alternative constructor when you want to provide your own HTTP client implementation instead of the default one. The custom client is responsible for its own configuration (retries, timeouts, headers, etc.).

  ### Usage

  ```
  from apify_client import ApifyClient

  from apify_client.http_clients import HttpClient, HttpResponse



  class MyHttpClient(HttpClient):

      def call(self, *, method, url, **kwargs) -> HttpResponse:

          ...



  client = ApifyClient.with_custom_http_client(

      token='MY-APIFY-TOKEN',

      http_client=MyHttpClient(),

  )
  ```

  ***

  #### Parameters

  * ##### optionaltoken: str | None = <!-- -->None

    The Apify API token.

  * ##### optionalkeyword-onlyapi\_url: str = <!-- -->DEFAULT\_API\_URL

    The URL of the Apify API server to connect to. Defaults to <https://api.apify.com>.

  * ##### optionalkeyword-onlyapi\_public\_url: str | None = <!-- -->DEFAULT\_API\_URL

    The globally accessible URL of the Apify API server. Defaults to <https://api.apify.com>.

  * ##### keyword-onlyhttp\_client: [HttpClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/HttpClient.md)

    A custom HTTP client instance extending `HttpClient`.

  #### Returns [ApifyClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/ApifyClient.md)

## Properties<!-- -->[**](#Properties)

### [**](#http_client)http\_client

**http\_client: [HttpClient](https://docs.apify.com/api/client/python/api/client/python/reference/class/HttpClient.md)

The HTTP client instance used for API communication.

Returns the custom HTTP client if one was provided via `with_custom_http_client`, or the default `ImpitHttpClient` otherwise (lazily created on first access).

### [**](#token)token

**token: str | None

The Apify API token used by the client.
