Skip to content

Commit 13fb2fc

Browse files
committed
Align structure in all versions
1 parent 0231e08 commit 13fb2fc

21 files changed

Lines changed: 414 additions & 395 deletions

website/docusaurus.config.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,21 @@ module.exports = {
7272
title: 'SDK for Python',
7373
items: [
7474
{
75-
to: 'docs/overview',
75+
type: 'doc',
76+
docId: 'introduction/introduction',
7677
label: 'Docs',
7778
position: 'left',
7879
activeBaseRegex: '/docs(?!/changelog)',
7980
},
8081
{
81-
to: '/reference',
82+
type: 'custom-versioned-reference',
8283
label: 'Reference',
8384
position: 'left',
8485
activeBaseRegex: '/reference',
8586
},
8687
{
87-
to: 'docs/changelog',
88+
type: 'doc',
89+
docId: 'changelog',
8890
label: 'Changelog',
8991
position: 'left',
9092
activeBaseRegex: '/docs/changelog',
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import OriginalComponentTypes from '@theme-original/NavbarItem/ComponentTypes';
2+
import VersionedReferenceNavbarItem from './VersionedReferenceNavbarItem';
3+
4+
export default {
5+
...OriginalComponentTypes,
6+
'custom-versioned-reference': VersionedReferenceNavbarItem,
7+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react';
2+
import { useDocsVersionCandidates } from '@docusaurus/plugin-content-docs/client';
3+
import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
4+
5+
/* eslint-disable react/prop-types */
6+
export default function VersionedReferenceNavbarItem({ docsPluginId, ...props }) {
7+
const [version] = useDocsVersionCandidates(docsPluginId);
8+
9+
// Latest version → /reference, "current" (next) → /reference/next, others → /reference/{name}
10+
let to = '/reference';
11+
if (!version.isLast) {
12+
to = `/reference/${version.name === 'current' ? 'next' : version.name}`;
13+
}
14+
15+
return <DefaultNavbarItem {...props} to={to} />;
16+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
id: introduction
3+
title: Overview
4+
sidebar_label: Overview
5+
slug: /overview
6+
description: 'The official library for creating Apify Actors in Python, providing tools for web scraping, automation, and data storage integration.'
7+
---
8+
9+
The Apify SDK for Python is the official library for creating [Apify Actors](https://docs.apify.com/platform/actors) in Python.
10+
11+
```python
12+
from apify import Actor
13+
from bs4 import BeautifulSoup
14+
import requests
15+
16+
async def main():
17+
async with Actor:
18+
actor_input = await Actor.get_input()
19+
response = requests.get(actor_input['url'])
20+
soup = BeautifulSoup(response.content, 'html.parser')
21+
await Actor.push_data({ 'url': actor_input['url'], 'title': soup.title.string })
22+
```
23+
24+
## What are Actors?
25+
26+
Actors are serverless cloud programs that can do almost anything a human can do in a web browser. They can do anything from small tasks such as filling in forms or unsubscribing from online services, all the way up to scraping and processing vast numbers of web pages.
27+
28+
Actors can be run either locally, or on the [Apify platform](https://docs.apify.com/platform/), where you can run them at scale, monitor them, schedule them, and even publish and monetize them.
29+
30+
If you're new to Apify, learn [what is Apify](https://docs.apify.com/platform/about) in the Apify platform documentation.
31+
32+
## Quick start
33+
34+
To create and run Actors through Apify Console, see the [Console documentation](https://docs.apify.com/academy/getting-started/creating-actors#choose-your-template). For creating and running Python Actors locally, refer to the [quick start guide](./quick-start).
35+
36+
Explore the Guides section in the sidebar for a deeper understanding of the SDK's features and best practices.
37+
38+
## Installation
39+
40+
The Apify SDK for Python requires Python version 3.8 or above. It is typically installed when you create a new Actor project using the [Apify CLI](https://docs.apify.com/cli). To install it manually in an existing project, use:
41+
42+
```bash
43+
pip install apify
44+
```
45+
46+
:::note API client alternative
47+
48+
If you need to interact with the Apify API programmatically without creating Actors, use the [Apify API client for Python](https://docs.apify.com/api/client/python) instead.
49+
50+
:::
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
---
2+
id: quick-start
3+
title: Quick start
4+
sidebar_label: Quick start
5+
description: 'Get started with the Apify SDK for Python by creating your first Actor and learning the basics.'
6+
---
7+
8+
Learn how to create and run Actors using the Apify SDK for Python.
9+
10+
---
11+
12+
import Tabs from '@theme/Tabs';
13+
import TabItem from '@theme/TabItem';
14+
import CodeBlock from '@theme/CodeBlock';
15+
16+
## Step 1: Create Actors
17+
18+
To create and run Actors through Apify Console, see the [Console documentation](https://docs.apify.com/academy/getting-started/creating-actors#choose-your-template).
19+
20+
To create a new Apify Actor on your computer, you can use the [Apify CLI](https://docs.apify.com/cli), and select one of the [Python Actor templates](https://apify.com/templates?category=python).
21+
22+
For example, to create an Actor from the "[beta] Python SDK" template, you can use the [`apify create` command](https://docs.apify.com/cli/docs/reference#apify-create-actorname).
23+
24+
```bash
25+
apify create my-first-actor --template python-start
26+
```
27+
28+
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.
29+
30+
## Step 2: Run Actors
31+
32+
To run the Actor, you can use the [`apify run` command](https://docs.apify.com/cli/docs/reference#apify-run):
33+
34+
```bash
35+
cd my-first-actor
36+
apify run
37+
```
38+
39+
This command:
40+
41+
- Activates the virtual environment in `.venv` (if no other virtual environment is activated yet)
42+
- Starts the Actor with the appropriate environment variables for local running
43+
- Configures it to use local storages from the `storage` folder
44+
45+
The Actor input, for example, will be in `storage/key_value_stores/default/INPUT.json`.
46+
47+
## Step 3: Understand Actor structure
48+
49+
All Python Actor templates follow the same structure.
50+
51+
The `.actor` directory contains the [Actor configuration](https://docs.apify.com/platform/actors/development/actor-config), such as the Actor's definition and input schema, and the Dockerfile necessary to run the Actor on the Apify platform.
52+
53+
The Actor's runtime dependencies are specified in the `requirements.txt` file, which follows the [standard requirements file format](https://pip.pypa.io/en/stable/reference/requirements-file-format/).
54+
55+
The Actor's source code is in the `src` folder. This folder contains two important files:
56+
57+
- `main.py` - which contains the main function of the Actor
58+
- `__main__.py` - which is the entrypoint of the Actor package, setting up the Actor [logger](../concepts/logging) and executing the Actor's main function via [`asyncio.run()`](https://docs.python.org/3/library/asyncio-runner.html#asyncio.run).
59+
60+
<Tabs>
61+
<TabItem value="main.py" label="main.py" default>
62+
<CodeBlock language="python">{
63+
`from apify import Actor
64+
${''}
65+
async def main():
66+
async with Actor:
67+
Actor.log.info('Actor input:', await Actor.get_input())
68+
await Actor.set_value('OUTPUT', 'Hello, world!')`
69+
}</CodeBlock>
70+
</TabItem>
71+
<TabItem value="__main__.py" label="__main.py__">
72+
<CodeBlock language="python">{
73+
`import asyncio
74+
import logging
75+
${''}
76+
from apify.log import ActorLogFormatter
77+
${''}
78+
from .main import main
79+
${''}
80+
handler = logging.StreamHandler()
81+
handler.setFormatter(ActorLogFormatter())
82+
${''}
83+
apify_logger = logging.getLogger('apify')
84+
apify_logger.setLevel(logging.DEBUG)
85+
apify_logger.addHandler(handler)
86+
${''}
87+
asyncio.run(main())`
88+
}</CodeBlock>
89+
</TabItem>
90+
</Tabs>
91+
92+
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.
93+
94+
## Step 4: Add dependencies {#adding-dependencies}
95+
96+
Adding dependencies into the Actor is simple.
97+
98+
First, add them in the [`requirements.txt`](https://pip.pypa.io/en/stable/reference/requirements-file-format/) file in the Actor source folder.
99+
100+
Then activate the virtual environment in `.venv`:
101+
102+
<Tabs groupId="operating-systems">
103+
<TabItem value="unix" label="Linux / macOS" default>
104+
<CodeBlock language="bash">{
105+
`source .venv/bin/activate`
106+
}</CodeBlock>
107+
</TabItem>
108+
<TabItem value="win" label="Windows">
109+
<CodeBlock language="powershell">{
110+
`.venv\\Scripts\\activate`
111+
}</CodeBlock>
112+
</TabItem>
113+
</Tabs>
114+
115+
Then install the dependencies:
116+
117+
```bash
118+
python -m pip install -r requirements.txt
119+
```
120+
121+
## Next steps
122+
123+
### Guides
124+
125+
To see how you can integrate the Apify SDK with some of the most popular web scraping libraries, check out our guides for working with:
126+
127+
- [Requests or HTTPX](../guides/requests-and-httpx)
128+
- [Beautiful Soup](../guides/beautiful-soup)
129+
- [Playwright](../guides/playwright)
130+
- [Selenium](../guides/selenium)
131+
- [Scrapy](../guides/scrapy)
132+
133+
### Concepts
134+
135+
To learn more about the features of the Apify SDK and how to use them, check out the Concepts section in the sidebar, especially the guides for:
136+
137+
- [Actor lifecycle](../concepts/actor-lifecycle)
138+
- [Working with storages](../concepts/storages)
139+
- [Handling Actor events](../concepts/actor-events)
140+
- [How to use proxies](../concepts/proxy-management)

website/versioned_docs/version-1.7/01-overview/01-introduction.mdx

Lines changed: 0 additions & 69 deletions
This file was deleted.

website/versioned_docs/version-1.7/01-overview/02-running-locally.mdx

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)