Skip to content

Latest commit

 

History

History
102 lines (80 loc) · 4.54 KB

File metadata and controls

102 lines (80 loc) · 4.54 KB
id quick-start
title Quick start
description Get started with the Apify client for Python by running your first Actor and retrieving results.

Learn how to start Actors and retrieve their results using the Apify Client.


import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import CodeBlock from '@theme/CodeBlock';

import AuthAsyncExample from '!!raw-loader!./code/02_auth_async.py'; import AuthSyncExample from '!!raw-loader!./code/02_auth_sync.py'; import UsageAsyncExample from '!!raw-loader!./code/01_usage_async.py'; import UsageSyncExample from '!!raw-loader!./code/01_usage_sync.py'; import InputAsyncExample from '!!raw-loader!./code/03_input_async.py'; import InputSyncExample from '!!raw-loader!./code/03_input_sync.py'; import DatasetAsyncExample from '!!raw-loader!./code/03_dataset_async.py'; import DatasetSyncExample from '!!raw-loader!./code/03_dataset_sync.py';

Step 1: Authentication and initialization

To use the client, you need an API token. You can find your token under the Integrations tab in Apify Console. Copy the token and initialize the client by providing it as a parameter to the ApifyClient constructor.

{AuthAsyncExample} {AuthSyncExample}

:::warning Secure access

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.

:::

Step 2: Running your first Actor

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 Actor name and the Actor owner's username. Use the ActorClient to run the Actor and wait for it to complete. You can run both your own Actors and Actors from Apify Store.

{UsageAsyncExample} {UsageSyncExample}

Passing input to the Actor

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 method. Actors respect the input schema defined in the Actor's input schema.

{InputAsyncExample} {InputSyncExample}

Step 3: Getting results from the dataset

To get the results from the dataset, you can use the DatasetClient (ApifyClient.dataset) and 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).

{DatasetAsyncExample} {DatasetSyncExample}

:::note Dataset access

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.

:::