Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions docs/01_introduction/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
id: introduction
title: Overview
sidebar_label: Overview
slug: /
description: "The official Python library to access the Apify API, with automatic retries, async support, and comprehensive API coverage."
---

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

import UsageAsyncExample from '!!raw-loader!./code/01_usage_async.py';
import UsageSyncExample from '!!raw-loader!./code/01_usage_sync.py';

The Apify API client for Python is the official library to access the [Apify REST API](/api/v2) from your Python applications. It provides useful features like automatic retries and convenience functions that improve the experience of using the Apify API.

The client simplifies interaction with the Apify platform by providing:

- Intuitive methods for working with [Actors](/platform/actors), [datasets](/platform/storage/dataset), [key-value stores](/platform/storage/key-value-store), and other Apify resources
- Both synchronous and asynchronous interfaces for flexible integration
- Built-in [retries with exponential backoff](../02_concepts/05_retries.mdx) for failed requests
- Comprehensive API coverage with JSON encoding (UTF-8) for all requests and responses

## Prerequisites

`apify-client` requires Python 3.11 or higher. Python is available for download on the [official website](https://www.python.org/downloads/). Check your current Python version by running:

```bash
python --version
```

## Installation

The Apify client is available as the [`apify-client`](https://pypi.org/project/apify-client/) package on PyPI.

```bash
pip install apify-client
```

## Quick example

Here's an example showing how to run an Actor and retrieve its results:

<Tabs>
<TabItem value="AsyncExample" label="Async client" default>
<CodeBlock className="language-python">
{UsageAsyncExample}
</CodeBlock>
</TabItem>
<TabItem value="SyncExample" label="Sync client">
<CodeBlock className="language-python">
{UsageSyncExample}
</CodeBlock>
</TabItem>
</Tabs>

> You can find your API token in the [Integrations section](https://console.apify.com/account/integrations) of Apify Console. See the [Quick start guide](./quick-start.mdx) for more details on authentication.
106 changes: 106 additions & 0 deletions docs/01_introduction/quick-start.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
---
id: quick-start
title: Quick start
sidebar_label: 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 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](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.

<Tabs>
<TabItem value="AsyncExample" label="Async client" default>
<CodeBlock className="language-python">
{AuthAsyncExample}
</CodeBlock>
</TabItem>
<TabItem value="SyncExample" label="Sync client">
<CodeBlock className="language-python">
{AuthSyncExample}
</CodeBlock>
</TabItem>
</Tabs>

:::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()`](/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).

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.

<Tabs>
<TabItem value="AsyncExample" label="Async client" default>
<CodeBlock className="language-python">
{InputAsyncExample}
</CodeBlock>
</TabItem>
<TabItem value="SyncExample" label="Sync client">
<CodeBlock className="language-python">
{InputSyncExample}
</CodeBlock>
</TabItem>
</Tabs>

## Step 3: Get results from the dataset

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`).

<Tabs>
<TabItem value="AsyncExample" label="Async client" default>
<CodeBlock className="language-python">
{DatasetAsyncExample}
</CodeBlock>
</TabItem>
<TabItem value="SyncExample" label="Sync client">
<CodeBlock className="language-python">
{DatasetSyncExample}
</CodeBlock>
</TabItem>
</Tabs>

:::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](https://docs.apify.com/platform/actors/running/runs-and-builds#runs).

:::

## Next steps

### Concepts

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

- [Asyncio support](../02_concepts/01_async_support.mdx) - asynchronous programming with the client
- [Single and collection clients](../02_concepts/02_single_collection_clients.mdx) - resource clients and collection clients
- [Error handling](../02_concepts/04_error_handling.mdx) - automatic data extraction and error debugging
- [Retries](../02_concepts/05_retries.mdx) - automatic retries with exponential backoff
- [Pagination](../02_concepts/08_pagination.mdx) - iterating through large result sets

### Guides

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

- [Pass input to an Actor](../03_guides/01_passing_input_to_actor.mdx)
- [Retrieve Actor data](../03_guides/03_retrieve_actor_data.mdx)
- [Integrate with data libraries](../03_guides/04_integration_with_data_libraries.mdx)
156 changes: 0 additions & 156 deletions docs/01_overview/index.mdx

This file was deleted.

4 changes: 2 additions & 2 deletions website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = {
title: 'API Client for Python',
items: [
{
to: 'docs/overview',
to: 'docs',
label: 'Docs',
position: 'left',
activeBaseRegex: '/docs(?!/changelog)',
Expand Down Expand Up @@ -139,7 +139,7 @@ module.exports = {
...config.themeConfig.footer,
logo: {
...config.themeConfig.footer.logo,
href: 'docs/introduction/overview',
href: 'docs',
},
},
},
Expand Down
10 changes: 7 additions & 3 deletions website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ module.exports = {
sidebar: [
{
type: 'doc',
id: 'overview/overview',
id: 'introduction/introduction',
},
{
type: 'doc',
id: 'introduction/quick-start',
},
{
type: 'category',
Expand All @@ -17,12 +21,12 @@ module.exports = {
},
{
type: 'category',
label: 'Examples',
label: 'Guides',
collapsed: true,
items: [
{
type: 'autogenerated',
dirName: '03_examples',
dirName: '03_guides',
},
],
},
Expand Down
2 changes: 1 addition & 1 deletion website/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default function Home() {
const history = useHistory();

useEffect(() => {
history.replace('/api/client/python/docs/introduction/overview');
history.replace('/api/client/python/docs');
}, [history]);

return null;
Expand Down