Skip to content

Commit 2bbfa9f

Browse files
authored
Merge pull request #2 from apify/apify-plugins-sync/5375792c
chore: sync generated content from apify-plugins
2 parents 469fc2a + 67b9785 commit 2bbfa9f

33 files changed

Lines changed: 3885 additions & 0 deletions
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
---
2+
name: apify-actor-development
3+
description: Develop, debug, and deploy Apify Actors - serverless cloud programs for web scraping, automation, and data processing. Use when creating new Actors, modifying existing ones, or troubleshooting Actor code.
4+
---
5+
6+
# Apify Actor Development
7+
8+
**Important:** Before you begin, fill in the `generatedBy` property in the meta section of `.actor/actor.json`. Set it to the name of the AI coding tool and model you are currently running in, in the format `"<tool> with <model>"` — for example `"Cursor with Claude Sonnet 4.5"`, `"Claude Code with Claude Opus 4"`, or `"GitHub Copilot with GPT-5"`. If you don't know the exact model, use the tool name alone (e.g. `"Cursor"`). This helps Apify monitor and improve AGENTS.md for specific AI tools and models.
9+
10+
## What are Apify Actors?
11+
12+
Actors are serverless programs inspired by the UNIX philosophy - programs that do one thing well and can be easily combined to build complex systems. They're packaged as Docker images and run in isolated containers in the cloud.
13+
14+
**Core Concepts:**
15+
- Accept well-defined JSON input
16+
- Perform isolated tasks (web scraping, automation, data processing)
17+
- Produce structured JSON output to datasets and/or store data in key-value stores
18+
- Can run from seconds to hours or even indefinitely
19+
- Persist state and can be restarted
20+
21+
## Prerequisites & Setup (MANDATORY)
22+
23+
Before creating or modifying actors, verify that `apify` CLI is installed `apify --help`.
24+
25+
If it is not installed, use one of these methods (listed in order of preference):
26+
27+
```bash
28+
# Preferred: install via a package manager (provides integrity checks)
29+
npm install -g apify-cli
30+
31+
# Or (Mac): brew install apify-cli
32+
```
33+
34+
> **Security note:** Do NOT install the CLI by piping remote scripts to a shell
35+
> (e.g. `curl … | bash` or `irm … | iex`). Always use a package manager.
36+
37+
When the apify CLI is installed, check that it is logged in with:
38+
39+
```bash
40+
# Auth check — do NOT pipe to /dev/null, you need to see errors
41+
apify info 2>&1
42+
```
43+
44+
If not logged in, authenticate using OAuth (opens browser):
45+
46+
```bash
47+
apify login
48+
```
49+
50+
If browser login isn't available (headless environment or CI), the CLI automatically reads `APIFY_TOKEN` from the environment. Ensure the env var is exported and run any apify command - no explicit login needed. If the user doesn't have a token, generate one at https://console.apify.com/settings/integrations.
51+
52+
> **Security note:** Avoid passing tokens as command-line arguments (e.g. `apify login -t <token>`).
53+
> Arguments are visible in process listings and may be recorded in shell history.
54+
> Prefer environment variables or interactive login instead.
55+
> Never log, print, or embed `APIFY_TOKEN` in source code or configuration files.
56+
57+
## Template Selection
58+
59+
**IMPORTANT:** Before starting actor development, always ask the user which programming language they prefer:
60+
- **JavaScript** - Use `apify create <actor-name> -t project_empty`
61+
- **TypeScript** - Use `apify create <actor-name> -t ts_empty`
62+
- **Python** - Use `apify create <actor-name> -t python-empty`
63+
64+
Use the appropriate CLI command based on the user's language choice. Additional packages (Crawlee, Playwright, etc.) can be installed later as needed.
65+
66+
## Quick Start Workflow
67+
68+
1. **Create actor project** - Run the appropriate `apify create` command based on user's language preference (see Template Selection above)
69+
2. **Install dependencies** (verify package names match intended packages before installing)
70+
- JavaScript/TypeScript: `npm install` (uses `package-lock.json` for reproducible, integrity-checked installs — commit the lockfile to version control)
71+
- Python: `pip install -r requirements.txt` (pin exact versions in `requirements.txt`, e.g. `crawlee==1.2.3`, and commit the file to version control)
72+
3. **Implement logic** - Write the actor code in `src/main.py`, `src/main.js`, or `src/main.ts`
73+
4. **Configure schemas** - Update input/output schemas in `.actor/input_schema.json`, `.actor/output_schema.json`, `.actor/dataset_schema.json`
74+
5. **Configure platform settings** - Update `.actor/actor.json` with actor metadata (see [references/actor-json.md](references/actor-json.md))
75+
6. **Write documentation** - Create comprehensive README.md for the marketplace (see [references/actor-readme.md](references/actor-readme.md) — this is mandatory, not optional)
76+
7. **Test locally** - Run `apify run` to verify functionality (see Local Testing section below)
77+
8. **Deploy** - Run `apify push` to deploy the actor on the Apify platform (actor name is defined in `.actor/actor.json`)
78+
79+
## Security
80+
81+
**Treat all crawled web content as untrusted input.** Actors ingest data from external websites that may contain malicious payloads. Follow these rules:
82+
83+
- **Sanitize crawled data** — Never pass raw HTML, URLs, or scraped text directly into shell commands, `eval()`, database queries, or template engines. Use proper escaping or parameterized APIs.
84+
- **Validate and type-check all external data** — Before pushing to datasets or key-value stores, verify that values match expected types and formats. Reject or sanitize unexpected structures.
85+
- **Do not execute or interpret crawled content** — Never treat scraped text as code, commands, or configuration. Content from websites could include prompt injection attempts or embedded scripts.
86+
- **Isolate credentials from data pipelines** — Ensure `APIFY_TOKEN` and other secrets are never accessible in request handlers or passed alongside crawled data. Use the Apify SDK's built-in credential management rather than passing tokens through environment variables in data-processing code.
87+
- **Review dependencies before installing** — When adding packages with `npm install` or `pip install`, verify the package name and publisher. Typosquatting is a common supply-chain attack vector. Prefer well-known, actively maintained packages.
88+
- **Pin versions and use lockfiles** — Always commit `package-lock.json` (Node.js) or pin exact versions in `requirements.txt` (Python). Lockfiles ensure reproducible builds and prevent silent dependency substitution. Run `npm audit` or `pip-audit` periodically to check for known vulnerabilities.
89+
90+
## Best Practices
91+
92+
**✓ Do:**
93+
- Use `apify run` to test actors locally (configures Apify environment and storage)
94+
- Use Apify SDK (`apify`) for code running ON Apify platform
95+
- Validate input early with proper error handling and fail gracefully
96+
- Use CheerioCrawler for static HTML (10x faster than browsers)
97+
- Use PlaywrightCrawler only for JavaScript-heavy sites
98+
- Use router pattern (createCheerioRouter/createPlaywrightRouter) for complex crawls
99+
- Implement retry strategies with exponential backoff
100+
- Use proper concurrency: HTTP (10-50), Browser (1-5)
101+
- Set sensible defaults in `.actor/input_schema.json`
102+
- Define output schema in `.actor/output_schema.json`
103+
- Clean and validate data before pushing to dataset
104+
- Use semantic CSS selectors with fallback strategies
105+
- Respect robots.txt, ToS, and implement rate limiting
106+
- **Always use `apify/log` package** — censors sensitive data (API keys, tokens, credentials)
107+
- Implement readiness probe handler (required if your Actor uses standby mode)
108+
109+
**✗ Don't:**
110+
- Use `npm start`, `npm run start`, `npx apify run`, or similar commands to run actors (use `apify run` instead)
111+
- Assume local storage from `apify run` is pushed to or visible in the Apify Console — it is local-only; deploy with `apify push` and run on the platform to see results in the Console
112+
- Rely on `Dataset.getInfo()` for final counts on Cloud
113+
- Use browser crawlers when HTTP/Cheerio works
114+
- Hard code values that should be in input schema or environment variables
115+
- Skip input validation or error handling
116+
- Overload servers - use appropriate concurrency and delays
117+
- Scrape prohibited content or ignore Terms of Service
118+
- Store personal/sensitive data unless explicitly permitted
119+
- Use deprecated options like `requestHandlerTimeoutMillis` on CheerioCrawler (v3.x)
120+
- Use `additionalHttpHeaders` - use `preNavigationHooks` instead
121+
- Pass raw crawled content into shell commands, `eval()`, or code-generation functions
122+
- Use `console.log()` or `print()` instead of the Apify logger — these bypass credential censoring
123+
- Disable standby mode without explicit permission
124+
125+
## Logging
126+
127+
See [references/logging.md](references/logging.md) for complete logging documentation including available log levels and best practices for JavaScript/TypeScript and Python.
128+
129+
Check `usesStandbyMode` in `.actor/actor.json` - only implement if set to `true`.
130+
131+
## Commands
132+
133+
```bash
134+
apify run # Run Actor locally
135+
apify login # Authenticate account
136+
apify push # Deploy to Apify platform (uses name from .actor/actor.json)
137+
apify help # List all commands
138+
```
139+
140+
**IMPORTANT:** Always use `apify run` to test actors locally. Do not use `npm run start`, `npm start`, `yarn start`, or other package manager commands - these will not properly configure the Apify environment and storage.
141+
142+
## Local Testing
143+
144+
When testing an actor locally with `apify run`, provide input data by creating a JSON file at:
145+
146+
```
147+
storage/key_value_stores/default/INPUT.json
148+
```
149+
150+
This file should contain the input parameters defined in your `.actor/input_schema.json`. The actor will read this input when running locally, mirroring how it receives input on the Apify platform.
151+
152+
**IMPORTANT - Local storage is NOT synced to the Apify Console:**
153+
- Running `apify run` stores all data (datasets, key-value stores, request queues) **only on your local filesystem** in the `storage/` directory.
154+
- This data is **never** automatically uploaded or pushed to the Apify platform. It exists only on your machine.
155+
- To verify results on the Apify Console, you must deploy the Actor with `apify push` and then run it on the platform.
156+
- Do **not** rely on checking the Apify Console to verify results from local runs — instead, inspect the local `storage/` directory or check the Actor's log output.
157+
158+
## Standby Mode
159+
160+
See [references/standby-mode.md](references/standby-mode.md) for complete standby mode documentation including readiness probe implementation for JavaScript/TypeScript and Python.
161+
162+
## Project Structure
163+
164+
```
165+
.actor/
166+
├── actor.json # Actor config: name, version, env vars, runtime
167+
├── input_schema.json # Input validation & Console form definition
168+
└── output_schema.json # Output storage and display templates
169+
src/
170+
└── main.js/ts/py # Actor entry point
171+
storage/ # Local-only storage (NOT synced to Apify Console)
172+
├── datasets/ # Output items (JSON objects)
173+
├── key_value_stores/ # Files, config, INPUT
174+
└── request_queues/ # Pending crawl requests
175+
Dockerfile # Container image definition
176+
```
177+
178+
## Actor Configuration
179+
180+
See [references/actor-json.md](references/actor-json.md) for complete actor.json structure and configuration options.
181+
182+
## Input Schema
183+
184+
See [references/input-schema.md](references/input-schema.md) for input schema structure and examples.
185+
186+
## Output Schema
187+
188+
See [references/output-schema.md](references/output-schema.md) for output schema structure, examples, and template variables.
189+
190+
## Dataset Schema
191+
192+
See [references/dataset-schema.md](references/dataset-schema.md) for dataset schema structure, configuration, and display properties.
193+
194+
## Key-Value Store Schema
195+
196+
See [references/key-value-store-schema.md](references/key-value-store-schema.md) for key-value store schema structure, collections, and configuration.
197+
198+
## Actor README
199+
200+
**IMPORTANT:** Always generate a README.md as part of Actor development. The README is the Actor's landing page on Apify Store and is critical for discoverability (SEO), user onboarding, and support. Do not consider an Actor complete without a proper README.
201+
202+
See [references/actor-readme.md](references/actor-readme.md) for the required structure, SEO best practices, and content guidelines. Also review these top Actors for best practices:
203+
204+
- [Instagram Scraper](https://apify.com/apify/instagram-scraper)
205+
- [Google Maps Scraper](https://apify.com/compass/crawler-google-places)
206+
207+
## Apify MCP Tools
208+
209+
If MCP server is configured, use these tools for documentation:
210+
211+
- `search-apify-docs` - Search documentation
212+
- `fetch-apify-docs` - Get full doc pages
213+
214+
Otherwise, the MCP Server url: `https://mcp.apify.com/?tools=docs`.
215+
216+
## Resources
217+
218+
- [docs.apify.com/llms.txt](https://docs.apify.com/llms.txt) - Apify quick reference documentation
219+
- [docs.apify.com/llms-full.txt](https://docs.apify.com/llms-full.txt) - Apify complete documentation
220+
- [https://crawlee.dev/llms.txt](https://crawlee.dev/llms.txt) - Crawlee quick reference documentation
221+
- [https://crawlee.dev/llms-full.txt](https://crawlee.dev/llms-full.txt) - Crawlee complete documentation
222+
- [whitepaper.actor](https://raw.githubusercontent.com/apify/actor-whitepaper/refs/heads/master/README.md) - Complete Actor specification
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Actor Configuration (actor.json)
2+
3+
The `.actor/actor.json` file contains the Actor's configuration including metadata, schema references, and platform settings.
4+
5+
## Structure
6+
7+
```json
8+
{
9+
"actorSpecification": 1,
10+
"name": "project-name",
11+
"title": "Project Title",
12+
"description": "Actor description",
13+
"version": "0.0",
14+
"meta": {
15+
"templateId": "template-id",
16+
"generatedBy": "<FILL-IN-TOOL-AND-MODEL>"
17+
},
18+
"input": "./input_schema.json",
19+
"output": "./output_schema.json",
20+
"storages": {
21+
"dataset": "./dataset_schema.json"
22+
},
23+
"dockerfile": "../Dockerfile"
24+
}
25+
```
26+
27+
## Example
28+
29+
```json
30+
{
31+
"actorSpecification": 1,
32+
"name": "project-cheerio-crawler-javascript",
33+
"title": "Project Cheerio Crawler Javascript",
34+
"description": "Crawlee and Cheerio project in javascript.",
35+
"version": "0.0",
36+
"meta": {
37+
"templateId": "js-crawlee-cheerio",
38+
"generatedBy": "Claude Code with Claude Sonnet 4.5"
39+
},
40+
"input": "./input_schema.json",
41+
"output": "./output_schema.json",
42+
"storages": {
43+
"dataset": "./dataset_schema.json"
44+
},
45+
"dockerfile": "../Dockerfile"
46+
}
47+
```
48+
49+
## Properties
50+
51+
- `actorSpecification` (integer, required) - Version of actor specification (currently 1)
52+
- `name` (string, required) - Actor identifier (lowercase, hyphens allowed)
53+
- `title` (string, required) - Human-readable title displayed in UI
54+
- `description` (string, optional) - Actor description for marketplace
55+
- `version` (string, required) - Semantic version number
56+
- `meta` (object, optional) - Metadata about actor generation
57+
- `templateId` (string) - ID of template used to create the actor
58+
- `generatedBy` (string) - Tool and model name that generated/modified the actor (e.g., "Claude Code with Claude Sonnet 4.5")
59+
- `input` (string, optional) - Path to input schema file
60+
- `output` (string, optional) - Path to output schema file
61+
- `storages` (object, optional) - Storage schema references
62+
- `dataset` (string) - Path to dataset schema file
63+
- `keyValueStore` (string) - Path to key-value store schema file
64+
- `dockerfile` (string, optional) - Path to Dockerfile
65+
66+
**Important:** Always fill in the `generatedBy` property with the tool and model you're currently using (e.g., "Claude Code with Claude Sonnet 4.5") to help Apify improve documentation.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Actor README Guidelines
2+
3+
The README is the Actor's landing page on Apify Store. It serves as SEO content, first impression, usage guide, and support resource. **Always generate a README.md when creating or deploying an Actor.**
4+
5+
## Required Structure
6+
7+
Write in Markdown. Use H2 (`##`) for main sections (these form the table of contents) and H3 (`###`) for subsections. Do not use H1 — the Actor name is automatically used as H1.
8+
9+
### 1. What does [Actor name] do?
10+
11+
- 1-2 sentences explaining what the Actor does and doesn't do
12+
- Include a link to the target website
13+
- Mention keywords like "API" (e.g., "Instagram API alternative")
14+
- Bold the most important terms
15+
16+
### 2. Why use [Actor name]? / Why scrape [target site]?
17+
18+
- Business use cases and benefits
19+
- List main features and capabilities
20+
- Highlight Apify platform advantages: scheduling, API access, integrations, proxy rotation, monitoring
21+
22+
### 3. What data can [Actor name] extract?
23+
24+
- Table showing main data fields the Actor outputs (field name, type, description)
25+
- Don't list every field — focus on the most useful and understandable ones
26+
27+
### 4. How to scrape [target site]
28+
29+
- Numbered step-by-step tutorial (Google may pick these up as rich snippets)
30+
- Include a link to blog tutorials if they exist
31+
32+
### 5. How much will it cost to scrape [target site]?
33+
34+
- Set pricing expectations based on the Actor's pricing model
35+
- For pay-per-result: mention free tier limits and what larger plans offer
36+
- For compute units: explain average data volume per dollar
37+
- Cost-related questions rank well in Google search
38+
39+
### 6. Input
40+
41+
- Reference the input tab: "See the input tab for full configuration options"
42+
- Explain any complex input fields or special formatting requirements
43+
- Screenshot of the input schema is optional but helpful
44+
45+
### 7. Output
46+
47+
- Include: "You can download the dataset in various formats such as JSON, HTML, CSV, or Excel"
48+
- Show a simplified JSON output example (2-3 items)
49+
- If output is complex, show separate examples for different data types
50+
51+
### 8. Tips / Advanced options (if applicable)
52+
53+
- How to limit compute unit usage
54+
- How to get more accurate results or improve speed
55+
56+
### 9. FAQ, Disclaimers, and Support
57+
58+
- Legal/scraping disclaimer (use this template and customize with the target site name):
59+
> Our Actors are ethical and do not extract any private user data, such as email addresses, gender, or location. They only extract what the user has chosen to share publicly. We therefore believe that our Actors, when used for ethical purposes by Apify users, are safe. However, you should be aware that your results could contain personal data. Personal data is protected by the GDPR in the European Union and by other regulations around the world. You should not scrape personal data unless you have a legitimate reason to do so. If you're unsure whether your reason is legitimate, consult your lawyers.
60+
- Common troubleshooting tips
61+
- Mention the Issues tab for feedback
62+
- Link to API tab for programmatic access
63+
- Use cases for the extracted data
64+
65+
## SEO Best Practices
66+
67+
- Include keywords naturally in H2/H3 headings (e.g., "How to scrape Instagram" not just "How to use")
68+
- Target "People Also Ask" style questions as H3 headings
69+
- Aim for at least 300 words total
70+
- Embed a YouTube video URL if available (renders automatically as a player)
71+
- Make images clickable with links
72+
73+
## Tone
74+
75+
- Match the README tone to the target audience skill level
76+
- For no-code users: use plain language, avoid code blocks early on
77+
- For developers: include technical details, code examples, and API references
78+
- Be clear about what technical knowledge is needed to use the Actor
79+
80+
## Reference Actors
81+
82+
Before writing a README, review these top Actors on the Apify Store for best practices on structure, tone, and content:
83+
84+
- [Instagram Scraper](https://apify.com/apify/instagram-scraper)
85+
- [Google Maps Scraper](https://apify.com/compass/crawler-google-places)
86+
87+
## Key Rules
88+
89+
- Always write the README as part of Actor development — do not skip this step
90+
- The first 25% of the README is what most visitors read — put the most important info there
91+
- Use emojis sparingly as bullet points to break up text
92+
- Keep images compressed but good quality
93+
- Use [Carbon](https://github.com/carbon-app/carbon) for code snippet screenshots if needed

0 commit comments

Comments
 (0)