Skip to content

Usage

Workflow: Create, Run Locally, Deploy

1. Authenticate

bash
apify login

Opens a browser to authenticate with your Apify account, or accepts an API token directly.

2. Scaffold a new Actor

bash
apify create my-first-actor

The CLI prompts you to pick a template (JavaScript, TypeScript, Python, Crawlee-based crawler, etc.) and scaffolds the project into my-first-actor/.

3. Run locally

bash
cd my-first-actor
apify run

Executes the Actor locally with environment variables set for local storage. Results are written to storage/datasets/default/ and logged to the terminal.

4. Push to the cloud

bash
apify push

Builds and uploads the Actor to your Apify account. It becomes available to run from the Apify Console or via the API.

5. Run a published Actor from the cloud

bash
apify call apify/hello-world

Minimal Actor Example (JavaScript SDK)

This is the skeleton of every Actor. Create a file called main.js (or src/main.ts for TypeScript):

javascript
import { Actor, log } from 'apify';

await Actor.init();

// Read input (defined in input_schema.json or passed at runtime)
const input = await Actor.getInput();
log.info('Actor input received:', input);

// Do your scraping / processing here
const result = { message: 'Hello from Apify!', receivedInput: input };

// Push results to the dataset
await Actor.pushData(result);

log.info('Actor finished successfully.');
await Actor.exit();

Local input is read from storage/key_value_stores/default/INPUT.json. Create that file with your test input before running apify run.


Minimal Actor Example (Python SDK)

python
from apify import Actor

async def main():
    async with Actor:
        actor_input = await Actor.get_input()
        Actor.log.info('Input received: %s', actor_input)

        await Actor.push_data({'message': 'Hello from Apify!', 'input': actor_input})

Running a Store Actor via API Client (JavaScript)

Use the Apify API client to trigger any Actor from your own code without the CLI:

javascript
import { ApifyClient } from 'apify-client';

const client = new ApifyClient({ token: process.env.APIFY_TOKEN });

const run = await client.actor('apify/web-scraper').call({
  startUrls: [{ url: 'https://example.com' }],
  maxCrawlingDepth: 1,
});

const { items } = await client.dataset(run.defaultDatasetId).listItems();
console.log('Scraped items:', items);

Key Actor Lifecycle Methods (JavaScript SDK)

MethodPurpose
Actor.init()Initialize runtime, connect to platform storage
Actor.getInput()Read the Actor's input object
Actor.pushData(item)Append a record to the default dataset
Actor.setValue(key, value)Write to the key-value store
Actor.exit()Graceful shutdown with status reporting

MCP Server (for AI agents)

Apify provides an MCP server so AI agents can discover and run Actors:

Entry point: https://agi.apify.com

Supports agentic payment protocols, meaning agents can authorize and pay for Actor runs without a traditional account setup.