Skip to content

Latest commit

 

History

History
107 lines (79 loc) · 4.81 KB

File metadata and controls

107 lines (79 loc) · 4.81 KB
id quick-start
title Quick start
description Get started with the Apify API client for Python by running an Actor and retrieving results from its dataset.

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

import ApiLink from '@site/src/components/ApiLink';

import AuthAsyncExample from '!!raw-loader!./code/02_auth_async.py'; import AuthSyncExample from '!!raw-loader!./code/02_auth_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';

Learn how to authenticate, run Actors, and retrieve results using the Apify API client for Python.


Step 1: Authenticate the client

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 (MY-APIFY-TOKEN) 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: Run an Actor

To start an Actor, call the apify_client.actor() 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.

To define the Actor's input, pass a dictionary to the call() method that matches the Actor's input schema. The input can include URLs to scrape, search terms, or other configuration data.

{InputAsyncExample} {InputSyncExample}

Step 3: Get results from the dataset

To get the results from the dataset, call the apify_client.dataset() method with the dataset ID, then call list_items() to retrieve the data. 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.

:::

Next steps

Concepts

To learn more about how the client works, check out the Concepts section in the sidebar:

Guides

For practical examples of common tasks, see the Guides section: