Skip to main content

apify_client/
lib.rs

1//! # apify-client
2//!
3//! **Official, but experimental — AI-generated and AI-maintained.** This is an official Apify
4//! client, but it is experimental: it is generated and maintained by AI. Review the code before
5//! relying on it in production and report issues on the repository.
6//!
7//! An idiomatic Rust client for the [Apify API](https://docs.apify.com/api/v2).
8//!
9//! It provides a resource-oriented interface that mirrors the official
10//! [JavaScript](https://github.com/apify/apify-client-js) and Python clients: start from
11//! an [`ApifyClient`], then drill down into resources (Actors, runs, datasets, key-value
12//! stores, request queues, tasks, schedules, webhooks, the store, users and logs).
13//!
14//! ## Quick start
15//!
16//! ```no_run
17//! use apify_client::ApifyClient;
18//!
19//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
20//! let client = ApifyClient::new("my-api-token");
21//!
22//! // Start an Actor and wait for it to finish.
23//! let run = client
24//!     .actor("apify/hello-world")
25//!     .call::<serde_json::Value>(None, Default::default(), None)
26//!     .await?;
27//!
28//! // Read items from the run's default dataset.
29//! if let Some(dataset_id) = &run.default_dataset_id {
30//!     let items = client
31//!         .dataset(dataset_id)
32//!         .list_items::<serde_json::Value>(Default::default())
33//!         .await?;
34//!     println!("Got {} items", items.items.len());
35//! }
36//! # Ok(())
37//! # }
38//! ```
39//!
40//! ## Architecture
41//!
42//! - **Public interface**: [`ApifyClient`] and the resource clients in [`clients`].
43//! - **Replaceable transport**: the [`http_client::HttpBackend`] trait, with a default
44//!   [`http_client::ReqwestBackend`]. Swap it via
45//!   [`ApifyClientBuilder::http_backend`].
46//! - **Cross-cutting behaviour** (auth, `User-Agent`, retries with exponential backoff,
47//!   timeouts) lives in [`http_client::HttpClient`] and is applied to every request.
48
49#![warn(missing_docs)]
50
51mod client;
52pub mod clients;
53pub mod common;
54pub mod error;
55pub mod http_client;
56pub mod models;
57mod version;
58
59pub use client::{ApifyClient, ApifyClientBuilder};
60pub use common::{ListOptions, PaginationList, QueryParams, StorageListOptions};
61pub use error::{ApiError, ApifyClientError, ApifyClientResult};
62pub use version::{API_SPEC_VERSION, CLIENT_VERSION};
63
64// Re-export the most commonly used option/parameter types for ergonomic access.
65pub use clients::actor::{ActorBuildOptions, ActorStartOptions};
66pub use clients::actor_collection::ActorListOptions;
67pub use clients::dataset::{DatasetDownloadOptions, DatasetListItemsOptions, DownloadItemsFormat};
68pub use clients::key_value_store::{GetRecordOptions, GetRecordsOptions, ListKeysOptions};
69pub use clients::log::LogOptions;
70pub use clients::request_queue::ListRequestsOptions;
71pub use clients::run::{
72    LastRunOptions, RunChargeOptions, RunMetamorphOptions, RunResurrectOptions,
73};
74pub use clients::run_collection::RunListOptions;
75pub use clients::store_collection::StoreListOptions;
76
77// Compile-test the code snippets in the README and the external `docs/` pages so every
78// in-documentation code snippet stays valid and runnable. Pulling each Markdown file in as
79// a doctest source means `cargo test --doc` (the `Test examples` CI step) compiles every
80// `rust` fenced block; `no_run` blocks are compiled but not executed, runnable blocks run.
81#[doc = include_str!("../README.md")]
82#[cfg(doctest)]
83struct ReadmeDoctests;
84
85#[doc = include_str!("../docs/README.md")]
86#[cfg(doctest)]
87struct DocsReadmeDoctests;
88
89#[doc = include_str!("../docs/actors.md")]
90#[cfg(doctest)]
91struct DocsActorsDoctests;
92
93#[doc = include_str!("../docs/misc.md")]
94#[cfg(doctest)]
95struct DocsMiscDoctests;
96
97#[doc = include_str!("../docs/storages.md")]
98#[cfg(doctest)]
99struct DocsStoragesDoctests;
100
101#[doc = include_str!("../docs/runs.md")]
102#[cfg(doctest)]
103struct DocsRunsDoctests;
104
105#[doc = include_str!("../docs/builds.md")]
106#[cfg(doctest)]
107struct DocsBuildsDoctests;