Skip to content
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ To create and run Actors through Apify Console,
see the [Console documentation](https://docs.apify.com/academy/getting-started/creating-actors#choose-your-template).

To create and run Python Actors locally, check the documentation for
[how to create and run Python Actors locally](https://docs.apify.com/sdk/python/docs/quick-start).
[how to create and run Python Actors locally](https://docs.apify.com/sdk/python/docs/overview/running-locally).

## Guides

Expand Down
45 changes: 0 additions & 45 deletions docs/01_introduction/index.mdx

This file was deleted.

51 changes: 0 additions & 51 deletions docs/01_introduction/installation.mdx

This file was deleted.

76 changes: 65 additions & 11 deletions docs/01_introduction/quick-start.mdx → docs/01_overview/index.mdx
Original file line number Diff line number Diff line change
@@ -1,18 +1,47 @@
---
title: Quick start
sidebar_label: Quick start
description: 'Get started with the Apify SDK for Python by creating your first Actor and learning the basics.'
---

Learn how to create and run Actors using the Apify SDK for Python.

title: Overview
sidebar_label: Overview
---

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

## Step 1: Creating Actors
The Apify SDK for Python is the official library for creating [Apify Actors](https://docs.apify.com/platform/actors) in Python.

```py
from apify import Actor
from bs4 import BeautifulSoup
import requests

async def main():
async with Actor:
input = await Actor.get_input()
response = requests.get(input['url'])
soup = BeautifulSoup(response.content, 'html.parser')
await Actor.push_data({ 'url': input['url'], 'title': soup.title.string })
```

## Requirements

The Apify SDK requires Python version 3.10 or above to run Python Actors locally.

## Installation

The Apify Python SDK is available as [`apify`](https://pypi.org/project/apify/) package on PyPi. To install it, run:

```bash
pip install apify
```

When you create an Actor using the Apify CLI, the Apify SDK for Python is installed for you automatically.

If you are not developing Apify Actors and you just need to access the Apify API from Python,
consider using the [Apify API client for Python](/api/client/python) directly.

## Quick start

### Creating Actors

To create and run Actors in Apify Console, refer to the [Console documentation](/platform/actors/development/quick-start/web-ide).

Expand All @@ -26,9 +55,9 @@ apify create my-first-actor --template python-start

This will create a new folder called `my-first-actor`, download and extract the "Getting started with Python" Actor template there, create a virtual environment in `my-first-actor/.venv`, and install the Actor dependencies in it.

![actor create command run](./images/apify-create.gif)
![actor create command run](../01_overview/images/apify-create.gif)

## Step 2: Running the Actor
#### Running the Actor

To run the Actor, you can use the [`apify run` command](/cli/docs/reference#apify-run):

Expand All @@ -45,7 +74,7 @@ This command:

The Actor input, for example, will be in `storage/key_value_stores/default/INPUT.json`.

## Step 3: Understanding Actor structure
## Actor structure

All Python Actor templates follow the same structure.

Expand Down Expand Up @@ -93,6 +122,31 @@ asyncio.run(main())`
If you want to modify the Actor structure, you need to make sure that your Actor is executable as a module, via `python -m src`, as that is the command started by `apify run` in the Apify CLI.
We recommend keeping the entrypoint for the Actor in the `src/__main__.py` file.

## Adding dependencies

First, add the dependencies in the [`requirements.txt`](https://pip.pypa.io/en/stable/reference/requirements-file-format/) file in the Actor source folder.

Then activate the virtual environment in `.venv`:

<Tabs groupId="operating-systems">
<TabItem value="unix" label="Linux / macOS" default>
<CodeBlock language="bash">{
`source .venv/bin/activate`
}</CodeBlock>
</TabItem>
<TabItem value="win" label="Windows">
<CodeBlock language="powershell">{
`.venv\\Scripts\\activate`
}</CodeBlock>
</TabItem>
</Tabs>

Finally, install the dependencies:

```bash
python -m pip install -r requirements.txt
```

## Next steps

### Guides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ title: Running webserver in your Actor

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

import WebserverExample from '!!raw-loader!roa-loader!./code/07_webserver.py';
import WebserverExample from '!!raw-loader!roa-loader!./code/09_webserver.py';

Each Actor run on the Apify platform is assigned a unique hard-to-guess URL (for example `https://8segt5i81sokzm.runs.apify.net`), which enables HTTP access to an optional web server running inside the Actor run's container.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ title: Logging

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

import LogConfigExample from '!!raw-loader!roa-loader!./code/09_log_config.py';
import LoggerUsageExample from '!!raw-loader!roa-loader!./code/09_logger_usage.py';
import RedirectLog from '!!raw-loader!roa-loader!./code/09_redirect_log.py';
import RedirectLogExistingRun from '!!raw-loader!roa-loader!./code/09_redirect_log_existing_run.py';
import LogConfigExample from '!!raw-loader!roa-loader!./code/10_log_config.py';
import LoggerUsageExample from '!!raw-loader!roa-loader!./code/10_logger_usage.py';
import RedirectLog from '!!raw-loader!roa-loader!./code/10_redirect_log.py';
import RedirectLogExistingRun from '!!raw-loader!roa-loader!./code/10_redirect_log_existing_run.py';

The Apify SDK is logging useful information through the [`logging`](https://docs.python.org/3/library/logging.html) module from Python's standard library, into the logger with the name `apify`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ title: Actor configuration

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

import ConfigExample from '!!raw-loader!roa-loader!./code/10_config.py';
import ConfigExample from '!!raw-loader!roa-loader!./code/11_config.py';

The [`Actor`](../../reference/class/Actor) class gets configured using the [`Configuration`](../../reference/class/Configuration) class, which initializes itself based on the provided environment variables.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ title: Pay-per-event monetization
description: Monetize your Actors using the pay-per-event pricing model
---

import ActorChargeSource from '!!raw-loader!roa-loader!./code/11_actor_charge.py';
import ConditionalActorChargeSource from '!!raw-loader!roa-loader!./code/11_conditional_actor_charge.py';
import ActorChargeSource from '!!raw-loader!roa-loader!./code/12_actor_charge.py';
import ConditionalActorChargeSource from '!!raw-loader!roa-loader!./code/12_conditional_actor_charge.py';
import ApiLink from '@site/src/components/ApiLink';
import RunnableCodeBlock from '@site/src/components/RunnableCodeBlock';

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ scrapy = ["scrapy>=2.11.0"]
"Apify Homepage" = "https://apify.com"
"Changelog" = "https://docs.apify.com/sdk/python/docs/changelog"
"Discord" = "https://discord.com/invite/jyEM2PRvMU"
"Documentation" = "https://docs.apify.com/sdk/python/docs/introduction"
"Documentation" = "https://docs.apify.com/sdk/python/docs/overview/introduction"
"Homepage" = "https://docs.apify.com/sdk/python/"
"Issue Tracker" = "https://github.com/apify/apify-sdk-python/issues"
"Release Notes" = "https://docs.apify.com/sdk/python/docs/upgrading/upgrading-to-v2"
Expand Down
2 changes: 1 addition & 1 deletion website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module.exports = {
title: 'SDK for Python',
items: [
{
to: 'docs/introduction',
to: 'docs/overview',
label: 'Docs',
position: 'left',
activeBaseRegex: '/docs(?!/changelog)',
Expand Down
11 changes: 2 additions & 9 deletions website/sidebars.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
module.exports = {
sidebar: [
{
type: 'category',
label: 'Introduction',
collapsed: false,
items: [
{
type: 'autogenerated',
dirName: '01_introduction',
},
],
type: 'doc',
id: 'overview/index',
},
{
type: 'category',
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 @@ -35,7 +35,7 @@ function Hero() {
<div className="row">
<div className="col">
<div className={styles.heroButtons}>
<Link to="/docs/introduction" className={styles.getStarted}>Get Started</Link>
<Link to="/docs/overview" className={styles.getStarted}>Get Started</Link>
<iframe src="https://ghbtns.com/github-btn.html?user=apify&repo=apify-sdk-python&type=star&count=true&size=large" frameBorder="0" scrolling="0" width="170" height="30" title="GitHub"></iframe>
</div>
</div>
Expand Down