apify-actorization
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseApify Actorization
Apify项目Actor化
Actorization converts existing software into reusable serverless applications compatible with the Apify platform. Actors are programs packaged as Docker images that accept well-defined JSON input, perform an action, and optionally produce structured JSON output.
Actor化可将现有软件转换为可复用的无服务器应用,使其兼容Apify平台。Actors是打包为Docker镜像的程序,可接收定义明确的JSON输入、执行操作,并可选择性生成结构化JSON输出。
Quick Start
快速开始
- Run in project root
apify init - Wrap code with SDK lifecycle (see language-specific section below)
- Configure
.actor/input_schema.json - Test with
apify run --input '{"key": "value"}' - Deploy with
apify push
- 在项目根目录运行
apify init - 使用SDK生命周期包装代码(见下方语言特定章节)
- 配置
.actor/input_schema.json - 使用进行测试
apify run --input '{"key": "value"}' - 使用部署
apify push
When to Use This Skill
适用场景
- Converting an existing project to run on Apify platform
- Adding Apify SDK integration to a project
- Wrapping a CLI tool or script as an Actor
- Migrating a Crawlee project to Apify
- 将现有项目转换为可在Apify平台运行的程序
- 为项目添加Apify SDK集成
- 将CLI工具或脚本包装为Actor
- 将Crawlee项目迁移到Apify
Prerequisites
前置条件
Verify CLI is installed:
apifybash
apify --helpIf not installed:
bash
curl -fsSL https://apify.com/install-cli.sh | bash验证 CLI已安装:
apifybash
apify --help若未安装:
bash
curl -fsSL https://apify.com/install-cli.sh | bashOr (Mac): brew install apify-cli
或(Mac):brew install apify-cli
Or (Windows): irm https://apify.com/install-cli.ps1 | iex
或(Windows):irm https://apify.com/install-cli.ps1 | iex
Or: npm install -g apify-cli
或:npm install -g apify-cli
Verify CLI is logged in:
```bash
apify info # Should return your usernameIf not logged in, check if environment variable is defined. If not, ask the user to generate one at https://console.apify.com/settings/integrations, then:
APIFY_TOKENbash
apify login -t $APIFY_TOKEN
验证CLI已登录:
```bash
apify info # 应返回你的用户名若未登录,检查是否定义了环境变量。若未定义,请让用户在https://console.apify.com/settings/integrations生成该令牌,然后执行:
APIFY_TOKENbash
apify login -t $APIFY_TOKENActorization Checklist
Actor化检查清单
Copy this checklist to track progress:
- Step 1: Analyze project (language, entry point, inputs, outputs)
- Step 2: Run to create Actor structure
apify init - Step 3: Apply language-specific SDK integration
- Step 4: Configure
.actor/input_schema.json - Step 5: Configure (if applicable)
.actor/output_schema.json - Step 6: Update metadata
.actor/actor.json - Step 7: Test locally with
apify run - Step 8: Deploy with
apify push
复制此清单以跟踪进度:
- 步骤1:分析项目(语言、入口点、输入、输出)
- 步骤2:运行创建Actor结构
apify init - 步骤3:应用语言特定的SDK集成
- 步骤4:配置
.actor/input_schema.json - 步骤5:配置(如适用)
.actor/output_schema.json - 步骤6:更新元数据
.actor/actor.json - 步骤7:使用本地测试
apify run - 步骤8:使用部署
apify push
Step 1: Analyze the Project
步骤1:分析项目
Before making changes, understand the project:
- Identify the language - JavaScript/TypeScript, Python, or other
- Find the entry point - The main file that starts execution
- Identify inputs - Command-line arguments, environment variables, config files
- Identify outputs - Files, console output, API responses
- Check for state - Does it need to persist data between runs?
在进行更改前,先了解项目:
- 确定语言 - JavaScript/TypeScript、Python或其他语言
- 找到入口点 - 启动执行的主文件
- 识别输入 - 命令行参数、环境变量、配置文件
- 识别输出 - 文件、控制台输出、API响应
- 检查状态需求 - 是否需要在运行之间持久化数据?
Step 2: Initialize Actor Structure
步骤2:初始化Actor结构
Run in the project root:
bash
apify initThis creates:
- - Actor configuration and metadata
.actor/actor.json - - Input definition for the Apify Console
.actor/input_schema.json - (if not present) - Container image definition
Dockerfile
在项目根目录运行:
bash
apify init此命令将创建:
- - Actor配置和元数据
.actor/actor.json - - Apify控制台的输入定义
.actor/input_schema.json - (若不存在)- 容器镜像定义
Dockerfile
Step 3: Apply Language-Specific Changes
步骤3:应用语言特定更改
Choose based on your project's language:
- JavaScript/TypeScript: See js-ts-actorization.md
- Python: See python-actorization.md
- Other Languages (CLI-based): See cli-actorization.md
根据项目语言选择对应方式:
- JavaScript/TypeScript:查看js-ts-actorization.md
- Python:查看python-actorization.md
- 其他语言(基于CLI):查看cli-actorization.md
Quick Reference
快速参考
| Language | Install | Wrap Code |
|---|---|---|
| JS/TS | | |
| Python | | |
| Other | Use CLI in wrapper script | |
| 语言 | 安装方式 | 代码包装方式 |
|---|---|---|
| JS/TS | | |
| Python | | |
| 其他语言 | 在包装脚本中使用CLI | |
Steps 4-6: Configure Schemas
步骤4-6:配置Schema
See schemas-and-output.md for detailed configuration of:
- Input schema ()
.actor/input_schema.json - Output schema ()
.actor/output_schema.json - Actor configuration ()
.actor/actor.json - State management (request queues, key-value stores)
Validate schemas against npm package.
@apify/json_schemas查看schemas-and-output.md以获取以下内容的详细配置:
- 输入Schema()
.actor/input_schema.json - 输出Schema()
.actor/output_schema.json - Actor配置()
.actor/actor.json - 状态管理(请求队列、键值存储)
使用 npm包验证Schema。
@apify/json_schemasStep 7: Test Locally
步骤7:本地测试
Run the actor with inline input (for JS/TS and Python actors):
bash
apify run --input '{"startUrl": "https://example.com", "maxItems": 10}'Or use an input file:
bash
apify run --input-file ./test-input.jsonImportant: Always use , not or . The CLI sets up the proper environment and storage.
apify runnpm startpython main.py使用内联输入运行Actor(适用于JS/TS和Python Actor):
bash
apify run --input '{"startUrl": "https://example.com", "maxItems": 10}'或使用输入文件:
bash
apify run --input-file ./test-input.json重要提示:请始终使用,而非或。CLI会设置正确的环境和存储。
apify runnpm startpython main.pyStep 8: Deploy
步骤8:部署
bash
apify pushThis uploads and builds your actor on the Apify platform.
bash
apify push此命令将你的Actor上传并构建到Apify平台。
Monetization (Optional)
变现(可选)
After deploying, you can monetize your actor in the Apify Store. The recommended model is Pay Per Event (PPE):
- Per result/item scraped
- Per page processed
- Per API call made
Configure PPE in the Apify Console under Actor > Monetization. Charge for events in your code with .
await Actor.charge('result')Other options: Rental (monthly subscription) or Free (open source).
部署完成后,你可以在Apify商店中将你的Actor变现。推荐使用**按事件付费(PPE)**模式:
- 按抓取的结果/条目付费
- 按处理的页面数量付费
- 按调用的API次数付费
在Apify控制台的Actor > 变现页面配置PPE模式。在代码中通过来记录付费事件。
await Actor.charge('result')其他可选模式:租赁制(月度订阅)或免费(开源)。
Pre-Deployment Checklist
部署前检查清单
- exists with correct name and description
.actor/actor.json - validates against
.actor/actor.json(@apify/json_schemas)actor.schema.json - defines all required inputs
.actor/input_schema.json - validates against
.actor/input_schema.json(@apify/json_schemas)input.schema.json - defines output structure (if applicable)
.actor/output_schema.json - validates against
.actor/output_schema.json(@apify/json_schemas)output.schema.json - is present and builds successfully
Dockerfile - /
Actor.init()wraps main code (JS/TS)Actor.exit() - wraps main code (Python)
async with Actor: - Inputs are read via /
Actor.getInput()Actor.get_input() - Outputs use or key-value store
Actor.pushData() - executes successfully with test input
apify run - is set in actor.json meta section
generatedBy
- 存在且包含正确的名称和描述
.actor/actor.json - 通过
.actor/actor.json的@apify/json_schemas验证actor.schema.json - 定义了所有必填输入
.actor/input_schema.json - 通过
.actor/input_schema.json的@apify/json_schemas验证input.schema.json - 定义了输出结构(如适用)
.actor/output_schema.json - 通过
.actor/output_schema.json的@apify/json_schemas验证output.schema.json - 存在且可成功构建
Dockerfile - 主代码已用/
Actor.init()包装(JS/TS)Actor.exit() - 主代码已用包装(Python)
async with Actor: - 通过/
Actor.getInput()读取输入Actor.get_input() - 使用或键值存储输出内容
Actor.pushData() - 使用测试输入执行可成功完成
apify run - actor.json的meta部分已设置
generatedBy
Apify MCP Tools
Apify MCP工具
If MCP server is configured, use these tools for documentation:
- - Search documentation
search-apify-docs - - Get full doc pages
fetch-apify-docs
Otherwise, the MCP Server url: .
https://mcp.apify.com/?tools=docs若已配置MCP服务器,可使用以下工具获取文档:
- - 搜索文档
search-apify-docs - - 获取完整文档页面
fetch-apify-docs
否则,MCP Server地址为:。
https://mcp.apify.com/?tools=docsResources
资源
- Actorization Academy - Comprehensive guide
- Apify SDK for JavaScript - Full SDK reference
- Apify SDK for Python - Full SDK reference
- Apify CLI Reference - CLI commands
- Actor Specification - Complete specification
- Actor化学院 - 综合指南
- Apify SDK for JavaScript - 完整SDK参考
- Apify SDK for Python - 完整SDK参考
- Apify CLI参考 - CLI命令
- Actor规范 - 完整规范