|
| 1 | +--- |
| 2 | +id: getting-started |
| 3 | +title: Getting started |
| 4 | +--- |
| 5 | + |
| 6 | +import Tabs from '@theme/Tabs'; |
| 7 | +import TabItem from '@theme/TabItem'; |
| 8 | +import CodeBlock from '@theme/CodeBlock'; |
| 9 | + |
| 10 | +import UsageAsyncExample from '!!raw-loader!./code/01_usage_async.py'; |
| 11 | +import UsageSyncExample from '!!raw-loader!./code/01_usage_sync.py'; |
| 12 | +import InputAsyncExample from '!!raw-loader!./code/03_input_async.py'; |
| 13 | +import InputSyncExample from '!!raw-loader!./code/03_input_sync.py'; |
| 14 | +import DatasetAsyncExample from '!!raw-loader!./code/03_dataset_async.py'; |
| 15 | +import DatasetSyncExample from '!!raw-loader!./code/03_dataset_sync.py'; |
| 16 | + |
| 17 | +This guide will walk you through how to use the [Apify Client for Python](https://github.com/apify/apify-client-python) to run [Actors](https://apify.com/actors) on the [Apify platform](https://docs.apify.com/platform), provide input to them, and retrieve results from their datasets. You'll learn the basics of running serverless programs (we're calling them Actors) and managing their output efficiently. |
| 18 | + |
| 19 | +## Running your first Actor |
| 20 | + |
| 21 | +To start an Actor, you need its ID (e.g., `john-doe/my-cool-actor`) and an API token. The Actor's ID is a combination of the username and the Actor owner's username. Use the [`ActorClient`](/reference/class/ActorClient) to run the Actor and wait for it to complete. You can run both your own Actors and [Actors from Apify store](https://docs.apify.com/platform/actors/running/actors-in-store). |
| 22 | + |
| 23 | +<Tabs> |
| 24 | + <TabItem value="AsyncExample" label="Async client" default> |
| 25 | + <CodeBlock className="language-python"> |
| 26 | + {UsageAsyncExample} |
| 27 | + </CodeBlock> |
| 28 | + </TabItem> |
| 29 | + <TabItem value="SyncExample" label="Sync client"> |
| 30 | + <CodeBlock className="language-python"> |
| 31 | + {UsageSyncExample} |
| 32 | + </CodeBlock> |
| 33 | + </TabItem> |
| 34 | +</Tabs> |
| 35 | + |
| 36 | +## Providing input to Actor |
| 37 | + |
| 38 | +Actors often require input, such as URLs to scrape, search terms, or other configuration data. You can pass input as a JSON object when starting the Actor using the [`ActorClient.call`](/reference/class/ActorClient#call) method. Actors respect the input schema defined in the Actor's [input schema](https://docs.apify.com/platform/actors/development/actor-definition/input-schema). |
| 39 | + |
| 40 | +<Tabs> |
| 41 | + <TabItem value="AsyncExample" label="Async client" default> |
| 42 | + <CodeBlock className="language-python"> |
| 43 | + {InputAsyncExample} |
| 44 | + </CodeBlock> |
| 45 | + </TabItem> |
| 46 | + <TabItem value="SyncExample" label="Sync client"> |
| 47 | + <CodeBlock className="language-python"> |
| 48 | + {InputSyncExample} |
| 49 | + </CodeBlock> |
| 50 | + </TabItem> |
| 51 | +</Tabs> |
| 52 | + |
| 53 | +## Getting results from the dataset |
| 54 | + |
| 55 | +To get the results from the dataset, you can use the [`DatasetClient`](/reference/class/DatasetClient) ([`ApifyClient.dataset`](/reference/class/ApifyClient#dataset) ) and [`DatasetClient.list_items`](/reference/class/DatasetClient#list_items) method. You need to pass the dataset ID to define which dataset you want to access. You can get the dataset ID from the Actor's run dictionary (represented by `defaultDatasetId`). |
| 56 | + |
| 57 | +<Tabs> |
| 58 | + <TabItem value="AsyncExample" label="Async client" default> |
| 59 | + <CodeBlock className="language-python"> |
| 60 | + {InputAsyncExample} |
| 61 | + </CodeBlock> |
| 62 | + </TabItem> |
| 63 | + <TabItem value="SyncExample" label="Sync client"> |
| 64 | + <CodeBlock className="language-python"> |
| 65 | + {InputSyncExample} |
| 66 | + </CodeBlock> |
| 67 | + </TabItem> |
| 68 | +</Tabs> |
| 69 | + |
| 70 | +:::note Dataset access |
| 71 | + |
| 72 | +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). |
| 73 | + |
| 74 | +::: |
0 commit comments