apify-rs 0.1.0

A Rust client for the Apify API
Documentation

apify-rs

Rust client for the Apify platform API.

Apify is a web scraping and automation cloud platform. Users publish Actors (serverless programs) to the Apify Store, run them with a JSON input, and retrieve structured results from Datasets or Key-Value Stores.

This crate mirrors the Apify REST API v2 and provides an idiomatic, strongly-typed Rust interface for managing Actors, Tasks, and Runs.

Disclaimer

This project was written with the help of large language models (LLMs). It is not well tested in production, so please review and test thoroughly before using it for critical workloads.

Features

  • Resource-oriented clientsActorClient, TaskClient, and RunClient wrap related REST endpoints.
  • Typed modelsActor, Task, Run, and supporting structs with serde support.
  • Convenience helperswait_for_finish, synchronous run variants, typed dataset item retrieval, and exponential-backoff retries on 429.
  • CLI demo — a clap-powered binary (cargo run -- --help) showing how to create Tasks, start Runs, poll for completion, and read results.
  • Instagram example — ready-to-use structs and formatting helpers for the Instagram Profile Scraper Actor output.

Quick start

use apify_rs::ApifyClient;

let client = ApifyClient::new(std::env::var("APIFY_TOKEN")?);

// Run a task asynchronously
let run = client.tasks().run("my-task-id", None).await?;
println!("Started run {}", run.id);

// Poll until the run finishes
let finished = client.runs().wait_for_finish(&run.id, 5, 600).await?;
println!("Run finished with status {:?}", finished.status);

Installation

You can install the CLI or add the library to your project:

# Installs the `apify` binary
cargo install --locked apify-rs

# Adds the library to your Cargo.toml
cargo add apify-rs

Documentation

API documentation is hosted on docs.rs/apify-rs.

CLI usage

Set APIFY_TOKEN in your environment and run:

apify --help

When developing locally you can also use:

cargo run -- --help

Example workflow:

# Create an Instagram scraping task
apify task create --name my-instagram-task --usernames apify,rustlang

# Start the task and wait for completion
apify task run <TASK_ID> --wait

# Fetch the resulting dataset
apify run dataset <RUN_ID>

Project structure

Module Purpose
src/lib.rs Root crate, ApifyClient, ApifyClientBuilder
src/client.rs Low-level HttpClient with auth, JSON, retries
src/error.rs ApifyError enum mapping HTTP & API errors
src/models.rs Request/response structs and enums
src/resources/actors.rs List, get, and run Actors
src/resources/tasks.rs CRUD and run Tasks
src/resources/runs.rs Monitor Runs, fetch datasets, abort/resurrect
src/instagram.rs Typed Instagram output structs & formatting
src/main.rs CLI binary

Running tests

cargo test

License

This project is provided as-is for demonstration purposes. See the source files for individual licensing information.