### Install and Setup OpenClaw Apify Plugin Source: https://docs.apify.com/platform/integrations/openclaw Install the Apify plugin for OpenClaw, run the setup wizard, and restart the gateway. This enables your OpenClaw agents to use Apify Actors. ```bash openclaw plugins install @apify/apify-openclaw-plugin openclaw apify setup openclaw gateway restart ``` -------------------------------- ### Start and Wait for Actor Run (Async) Source: https://docs.apify.com/api/client/python/docs/2.5/concepts/convenience-methods Demonstrates how to start an Actor and wait for its completion using the asynchronous client. Includes an example of waiting with a specific timeout. ```python from apify_client import ApifyClientAsync TOKEN = 'MY-APIFY-TOKEN' async def main() -> None: apify_client = ApifyClientAsync(TOKEN) actor_client = apify_client.actor('username/actor-name') # Start an Actor and waits for it to finish finished_actor_run = await actor_client.call() # Starts an Actor and waits maximum 60s (1 minute) for the finish actor_run = await actor_client.start(wait_for_finish=60) ``` -------------------------------- ### Initialize TaskClient and Start/Call Task Source: https://docs.apify.com/api/client/js/reference/class/TaskClient Demonstrates how to initialize the ApifyClient, get a TaskClient instance, and then start or call a task. The 'start' method initiates a task run, while 'call' starts a task and waits for it to complete. ```javascript const client = new ApifyClient({ token: 'my-token' }); const taskClient = client.task('my-task-id'); // Start a task const run = await taskClient.start(); // Call a task and wait for it to finish const finishedRun = await taskClient.call(); ``` -------------------------------- ### Get Key-Value Store Record (Python) Source: https://docs.apify.com/api/v2/key-value-store-record-get Python example for fetching a record from a Key-Value Store. Ensure you have the 'apify-client' library installed. ```python from apify_client import ApifyClient # Use your API token or leave it empty for default configuration client = ApifyClient("YOUR_API_TOKEN") # Example call store_id = "storeId" key = "myKey" record = client.key_value_store(store_id).get_record(key) print(record) ``` -------------------------------- ### Start Interactive Apify Setup Source: https://docs.apify.com/platform/integrations/openclaw Run the setup wizard to configure your Apify API key interactively. The wizard prompts for your token, verifies the connection, and saves the configuration. ```bash openclaw apify setup ``` -------------------------------- ### BuildClient Example Source: https://docs.apify.com/api/client/js/reference/class/BuildClient Demonstrates how to initialize the BuildClient, get build details, wait for a build to complete, and access its logs. ```javascript const client = new ApifyClient({ token: 'my-token' }); const buildClient = client.build('my-build-id'); // Get build details const build = await buildClient.get(); // Wait for the build to finish const finishedBuild = await buildClient.waitForFinish(); // Access build logs const log = await buildClient.log().get(); ``` -------------------------------- ### Python Web Server Example for Apify Actor Source: https://docs.apify.com/sdk/python/docs/guides/running-webserver This example shows how to start a simple web server in your Actor. It responds to every GET request with the number of items the Actor has processed so far. Ensure the 'http.server' module is available in your environment. ```python import asyncio from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer from apify import Actor processed_items = 0 http_server = None class RequestHandler(BaseHTTPRequestHandler): """A handler that prints the number of processed items on every GET request.""" def do_GET(self) -> None: self.log_request() self.send_response(200) self.end_headers() self.wfile.write(bytes(f'Processed items: {processed_items}', encoding='utf-8')) def run_server() -> None: """Start the HTTP server and keep a reference to it.""" global http_server with ThreadingHTTPServer( ('', Actor.configuration.web_server_port), RequestHandler ) as server: Actor.log.info(f'Server running on {Actor.configuration.web_server_port}') http_server = server server.serve_forever() async def main() -> None: global processed_items async with Actor: # Start the HTTP server in a separate thread. run_server_task = asyncio.get_running_loop().run_in_executor(None, run_server) # Simulate doing some work. for _ in range(100): await asyncio.sleep(1) processed_items += 1 Actor.log.info(f'Processed items: {processed_items}') if http_server is None: raise RuntimeError('HTTP server not started') # Signal the server to shut down and wait. http_server.shutdown() await run_server_task if __name__ == '__main__': asyncio.run(main()) ``` -------------------------------- ### Example Response Schema (Started At) Source: https://docs.apify.com/api/v2/actor-task-runs-last-abort-post An example of the 'startedAt' field within the response schema, indicating the time when the Actor run started. ```string 2019-11-30T07:34:24.202Z ``` -------------------------------- ### Verify Python project setup Source: https://docs.apify.com/academy/scraping-basics-python/downloading-html Create a main.py file and import httpx to confirm that the Python environment and the httpx library are installed correctly. Running this script should output 'OK'. ```python import httpx print("OK") ``` -------------------------------- ### Python Quickstart with Requests Source: https://docs.apify.com/proxy Demonstrates using Apify Proxy with the Python SDK and the `requests` library. It creates a proxy configuration, obtains a proxy URL, and makes a GET request using the proxy. ```python import requests, asyncio from apify import Actor async def main(): async with Actor: proxy_configuration = await Actor.create_proxy_configuration() proxy_url = await proxy_configuration.new_url() proxies = { 'http': proxy_url, 'https': proxy_url, } response = requests.get('https://api.apify.com/v2/browser-info', proxies=proxies) print(response.text) if __name__ == '__main__': asyncio.run(main()) ``` -------------------------------- ### Get and Start Actor Runs Source: https://docs.apify.com/api/client/js/docs/concepts/usage-patterns Shows how to get a specific actor client and start a new run for it. Resources can be identified by username/actor-name. Requires an Apify API token. ```javascript import { ApifyClient } from 'apify-client'; const client = new ApifyClient({ token: 'MY-APIFY-TOKEN' }); // Resource clients accept an ID of the resource. const actorClient = client.actor('username/actor-name'); // Fetches the john-doe/my-actor object from the API. const myActor = await actorClient.get(); // Starts the run of john-doe/my-actor and returns the Run object. const myActorRun = await actorClient.start(); ``` -------------------------------- ### Test Project Setup with Basic Imports Source: https://docs.apify.com/academy/scraping-basics-javascript/legacy/data-extraction/project-setup Create a main.js file and add this code to verify that the installed libraries can be imported and that your project is working correctly. Run with 'node main.js'. ```javascript import { gotScraping } from 'got-scraping'; import * as cheerio from 'cheerio'; console.log('it works!'); ``` -------------------------------- ### Async Client: Get and Start Actor Source: https://docs.apify.com/api/client/python/docs/2.5/concepts/single-and-collection-clients Shows how to get details of a specific Actor and start a new run for it using the asynchronous client. The Actor can be identified by its ID or username/resource-name. ```python from apify_client import ApifyClientAsync TOKEN = 'MY-APIFY-TOKEN' async def main() -> None: apify_client = ApifyClientAsync(TOKEN) # Resource clients accept an ID of the resource actor_client = apify_client.actor('username/actor-name') # Fetch the 'username/actor-name' object from the API my_actor = await actor_client.get() # Start the run of 'username/actor-name' and return the Run object my_actor_run = await actor_client.start() ``` -------------------------------- ### Initialize Project and Add Apify SDK with uv Source: https://docs.apify.com/sdk/python/docs/guides/uv Use these commands to create a new project, set the Python version, and add the Apify SDK as a dependency. uv resolves and installs the dependency tree. ```bash uv init my-actor --bare cd my-actor uv python pin 3.14 uv add apify ``` -------------------------------- ### Start and Wait for Actor Run - JavaScript Source: https://docs.apify.com/api/client/js/reference/class/ActorClient Starts an Actor run and waits for its completion. The first example runs an Actor and logs its status and dataset ID. The second example includes a timeout and streams logs to the console. The third example uses a custom Log instance for streaming. ```javascript const run = await client.actor('my-actor').call({ url: 'https://example.com' }); console.log(`Run finished with status: ${run.status}`); console.log(`Dataset ID: ${run.defaultDatasetId}`); ``` ```javascript const run = await client.actor('my-actor').call( { url: 'https://example.com' }, { waitSecs: 300, log: 'default' } ); ``` ```javascript import { Log } from '@apify/log'; const log = new Log({ prefix: 'My Actor' }); const run = await client.actor('my-actor').call({ url: 'https://example.com' }, { log }); ``` -------------------------------- ### Example Usage Source: https://docs.apify.com/sdk/js/reference/class/PlatformEventManager Demonstrates how to subscribe to the 'cpuInfo' event to monitor CPU load. ```APIDOC Actor.on('cpuInfo', (data) => { if (data.isCpuOverloaded) console.log('Oh no, the CPU is overloaded!'); }); ``` -------------------------------- ### Full Example: Run Actor and Download Dataset Items (Python) Source: https://docs.apify.com/academy/getting-started/apify-client Complete example demonstrating how to initialize the ApifyClient, call an Actor, retrieve its dataset, and download its items. Replace placeholders with your actual token and Actor name. ```python # client.py from apify_client import ApifyClient client = ApifyClient(token='YOUR_TOKEN') actor = client.actor('YOUR_USERNAME/adding-actor').call(run_input={ 'num1': 4, 'num2': 2 }) dataset = client.dataset(run['defaultDatasetId']) items = dataset.list_items().items print(items) ``` -------------------------------- ### Build an Actor Version - JavaScript Source: https://docs.apify.com/api/client/js/reference/class/ActorClient Starts a new build for a specified Actor version. The first example starts a build and returns immediately. The second example waits for the build to finish, optionally setting a tag and using cache. ```javascript const build = await client.actor('my-actor').build('0.1'); console.log(`Build ${build.id} started with status: ${build.status}`); ``` ```javascript const build = await client.actor('my-actor').build('0.1', { waitForFinish: 120, tag: 'latest', useCache: true }); ``` -------------------------------- ### Get Default Build Client - JavaScript Source: https://docs.apify.com/api/client/js/reference/class/ActorClient Obtains a client for the Actor's default build. The first example fetches build details after getting the client. The second example waits for the default build to finish within a specified timeout. ```javascript const buildClient = await client.actor('my-actor').defaultBuild(); const build = await buildClient.get(); console.log(`Default build status: ${build.status}`); ``` ```javascript const buildClient = await client.actor('my-actor').defaultBuild({ waitForFinish: 60 }); const build = await buildClient.get(); ``` -------------------------------- ### Basic Setup with Puppeteer Source: https://docs.apify.com/academy/puppeteer-playwright/common-use-cases/paginating-through-results Initializes Puppeteer, opens a new page, and navigates to the target URL. This is the starting point for scraping. ```javascript import puppeteer from 'puppeteer'; // Create an array where all scraped products will // be pushed to const products = []; const browser = await puppeteer.launch({ headless: false }); const page = await browser.newPage(); await page.goto('https://www.aboutyou.com/c/women/clothing-20204'); await browser.close(); ``` -------------------------------- ### Install MCP Python SDK Source: https://docs.apify.com/platform/integrations/mcp-connectors/use-in-actors Install the official MCP Python SDK and its dependencies using pip. This is required for the Python example. ```bash pip install mcp httpx apify ``` -------------------------------- ### Full Example: Run Actor and Download Dataset Items (Node.js) Source: https://docs.apify.com/academy/getting-started/apify-client Complete example demonstrating how to initialize the ApifyClient, call an Actor, retrieve its dataset, and download its items. Replace placeholders with your actual token and Actor name. ```javascript // client.js import { ApifyClient } from 'apify-client'; const client = new ApifyClient({ token: 'YOUR_TOKEN', }); const run = await client.actor('YOUR_USERNAME/adding-actor').call({ num1: 4, num2: 2, }); const dataset = client.dataset(run.defaultDatasetId); const { items } = await dataset.listItems(); console.log(items); ``` -------------------------------- ### Initialize Project and Install Dependencies Source: https://docs.apify.com/academy/api-scraping/graphql-scraping/custom-queries Initializes an npm project and installs graphql-tag, puppeteer, and got-scraping packages. ```shell npm init -y && npm install graphql-tag puppeteer got-scraping ``` -------------------------------- ### Install MCP TypeScript SDK Source: https://docs.apify.com/platform/integrations/mcp-connectors/use-in-actors Install the official MCP TypeScript SDK using npm. This is required to use the TypeScript example. ```bash npm install @modelcontextprotocol/sdk ``` -------------------------------- ### Start and Wait for Actor Run (Sync) Source: https://docs.apify.com/api/client/python/docs/2.5/concepts/convenience-methods Illustrates how to start an Actor and wait for its completion using the synchronous client. Shows an example of setting a maximum wait time for the Actor run. ```python from apify_client import ApifyClient TOKEN = 'MY-APIFY-TOKEN' def main() -> None: apify_client = ApifyClient(TOKEN) actor_client = apify_client.actor('username/actor-name') # Start an Actor and waits for it to finish finished_actor_run = actor_client.call() # Starts an Actor and waits maximum 60s (1 minute) for the finish actor_run = actor_client.start(wait_for_finish=60) ``` -------------------------------- ### GET Request Example Source: https://docs.apify.com/api/v2/dataset-statistics-get This is the basic structure of the GET request to retrieve dataset statistics. Replace ':datasetId' with the actual dataset ID. ```http GET https://api.apify.com/v2/datasets/:datasetId/statistics ``` -------------------------------- ### Initialize Project and Install Packages Source: https://docs.apify.com/academy/api-scraping/general-api-scraping/handling-pagination Initializes a new Node.js project and installs the puppeteer and got-scraping packages. Run this command in your project's root directory. ```shell npm init -y && npm i puppeteer got-scraping ``` -------------------------------- ### Install Langflow with uv Source: https://docs.apify.com/platform/integrations/langflow Install the Langflow platform using the uv package and project manager. This is the recommended method for local setup. ```bash uv pip install langflow ```