|
| 1 | +--- |
| 2 | +id: quick-start |
| 3 | +title: Quick start |
| 4 | +sidebar_label: Quick start |
| 5 | +description: "Get started with the Apify API client for Python by running an Actor and retrieving results from its dataset." |
| 6 | +--- |
| 7 | + |
| 8 | +import Tabs from '@theme/Tabs'; |
| 9 | +import TabItem from '@theme/TabItem'; |
| 10 | +import CodeBlock from '@theme/CodeBlock'; |
| 11 | + |
| 12 | +import AuthAsyncExample from '!!raw-loader!./code/02_auth_async.py'; |
| 13 | +import AuthSyncExample from '!!raw-loader!./code/02_auth_sync.py'; |
| 14 | +import InputAsyncExample from '!!raw-loader!./code/03_input_async.py'; |
| 15 | +import InputSyncExample from '!!raw-loader!./code/03_input_sync.py'; |
| 16 | +import DatasetAsyncExample from '!!raw-loader!./code/03_dataset_async.py'; |
| 17 | +import DatasetSyncExample from '!!raw-loader!./code/03_dataset_sync.py'; |
| 18 | + |
| 19 | +Learn how to authenticate, run Actors, and retrieve results using the Apify API client for Python. |
| 20 | + |
| 21 | +--- |
| 22 | + |
| 23 | +## Step 1: Authenticate the client |
| 24 | + |
| 25 | +To use the client, you need an [API token](https://docs.apify.com/platform/integrations/api#api-token). You can find your token under the [Integrations](https://console.apify.com/account/integrations) tab in Apify Console. Copy the token and initialize the client by providing it (`MY-APIFY-TOKEN`) as a parameter to the `ApifyClient` constructor. |
| 26 | + |
| 27 | +<Tabs> |
| 28 | + <TabItem value="AsyncExample" label="Async client" default> |
| 29 | + <CodeBlock className="language-python"> |
| 30 | + {AuthAsyncExample} |
| 31 | + </CodeBlock> |
| 32 | + </TabItem> |
| 33 | + <TabItem value="SyncExample" label="Sync client"> |
| 34 | + <CodeBlock className="language-python"> |
| 35 | + {AuthSyncExample} |
| 36 | + </CodeBlock> |
| 37 | + </TabItem> |
| 38 | +</Tabs> |
| 39 | + |
| 40 | +:::warning Secure access |
| 41 | + |
| 42 | +The API token is used to authorize your requests to the Apify API. You can be charged for the usage of the underlying services, so do not share your API token with untrusted parties or expose it on the client side of your applications. |
| 43 | + |
| 44 | +::: |
| 45 | + |
| 46 | +## Step 2: Run an Actor |
| 47 | + |
| 48 | +To start an Actor, call the [`apify_client.actor()`](/reference/class/ActorClient) method with the Actor's ID (e.g., `john-doe/my-cool-actor`). The Actor's ID is a combination of the Actor owner's username and the Actor name. You can run both your own Actors and Actors from [Apify Store](https://apify.com/store). |
| 49 | + |
| 50 | +To define the Actor's input, pass a dictionary to the [`call()`](/reference/class/ActorClient#call) method that matches the Actor's [input schema](https://docs.apify.com/platform/actors/development/actor-definition/input-schema). The input can include URLs to scrape, search terms, or other configuration data. |
| 51 | + |
| 52 | +<Tabs> |
| 53 | + <TabItem value="AsyncExample" label="Async client" default> |
| 54 | + <CodeBlock className="language-python"> |
| 55 | + {InputAsyncExample} |
| 56 | + </CodeBlock> |
| 57 | + </TabItem> |
| 58 | + <TabItem value="SyncExample" label="Sync client"> |
| 59 | + <CodeBlock className="language-python"> |
| 60 | + {InputSyncExample} |
| 61 | + </CodeBlock> |
| 62 | + </TabItem> |
| 63 | +</Tabs> |
| 64 | + |
| 65 | +## Step 3: Get results from the dataset |
| 66 | + |
| 67 | +To get the results from the dataset, call the [`apify_client.dataset()`](/reference/class/DatasetClient) method with the dataset ID, then call [`list_items()`](/reference/class/DatasetClient#list_items) to retrieve the data. You can get the dataset ID from the Actor's run dictionary (represented by `defaultDatasetId`). |
| 68 | + |
| 69 | +<Tabs> |
| 70 | + <TabItem value="AsyncExample" label="Async client" default> |
| 71 | + <CodeBlock className="language-python"> |
| 72 | + {DatasetAsyncExample} |
| 73 | + </CodeBlock> |
| 74 | + </TabItem> |
| 75 | + <TabItem value="SyncExample" label="Sync client"> |
| 76 | + <CodeBlock className="language-python"> |
| 77 | + {DatasetSyncExample} |
| 78 | + </CodeBlock> |
| 79 | + </TabItem> |
| 80 | +</Tabs> |
| 81 | + |
| 82 | +:::note Dataset access |
| 83 | + |
| 84 | +Running an Actor might take time, depending on the Actor's complexity and the amount of data it processes. If you want only to get data and have an immediate response, you should access the existing dataset of the finished [Actor run](https://docs.apify.com/platform/actors/running/runs-and-builds#runs). |
| 85 | + |
| 86 | +::: |
| 87 | + |
| 88 | +## Next steps |
| 89 | + |
| 90 | +### Concepts |
| 91 | + |
| 92 | +To learn more about how the client works, check out the Concepts section in the sidebar: |
| 93 | + |
| 94 | +- [Asyncio support](../02_concepts/01_async_support.mdx) - asynchronous programming with the client |
| 95 | +- [Single and collection clients](../02_concepts/02_single_collection_clients.mdx) - resource clients and collection clients |
| 96 | +- [Error handling](../02_concepts/04_error_handling.mdx) - automatic data extraction and error debugging |
| 97 | +- [Retries](../02_concepts/05_retries.mdx) - automatic retries with exponential backoff |
| 98 | +- [Pagination](../02_concepts/08_pagination.mdx) - iterating through large result sets |
| 99 | + |
| 100 | +### Guides |
| 101 | + |
| 102 | +For practical examples of common tasks, see the Guides section: |
| 103 | + |
| 104 | +- [Pass input to an Actor](../03_guides/01_passing_input_to_actor.mdx) |
| 105 | +- [Retrieve Actor data](../03_guides/03_retrieve_actor_data.mdx) |
| 106 | +- [Integrate with data libraries](../03_guides/04_integration_with_data_libraries.mdx) |
0 commit comments