Allscreenshots SDK for Rust
Official Rust SDK for the Allscreenshots API - capture website screenshots programmatically.
Installation
Add this to your Cargo.toml:
[]
= "0.1"
= { = "1", = ["full"] }
Quick start
use ;
async
Configuration
Environment variable
The SDK automatically reads the API key from the ALLSCREENSHOTS_API_KEY environment variable:
Builder pattern
Configure the client with custom options:
use AllscreenshotsClient;
use Duration;
let client = builder
.api_key
.base_url
.timeout
.max_retries
.build?;
API reference
Screenshot capture
Synchronous screenshot
use ;
let client = from_env?;
let request = builder
.url
.device
.full_page
.format
.quality
.dark_mode
.build?;
let image_bytes = client.screenshot.await?;
write?;
Asynchronous screenshot
For long-running screenshots, use the async API:
use ;
use Duration;
let client = from_env?;
let request = builder
.url
.full_page
.build?;
// Start the job
let job = client.screenshot_async.await?;
println!;
// Poll for completion
loop
Bulk screenshots
Capture multiple URLs in a single request:
use ;
let client = from_env?;
let request = new.with_defaults;
let bulk_job = client.create_bulk_job.await?;
println!;
// Check status
let status = client.get_bulk_job.await?;
println!;
Compose multiple screenshots
Combine multiple screenshots into a single image:
use ;
let client = from_env?;
let request = with_captures.with_output;
let result = client.compose.await?;
println!;
Scheduled screenshots
Set up recurring screenshot captures:
use ;
let client = from_env?;
let request = new
.with_timezone
.with_retention_days
.with_options;
let schedule = client.create_schedule.await?;
println!;
// List all schedules
let schedules = client.list_schedules.await?;
for s in schedules.schedules
// Pause a schedule
client.pause_schedule.await?;
// Resume a schedule
client.resume_schedule.await?;
// Get execution history
let history = client.get_schedule_history.await?;
for execution in history.executions
Usage and quota
Check your API usage:
use AllscreenshotsClient;
let client = from_env?;
// Get usage statistics
let usage = client.get_usage.await?;
println!;
println!;
println!;
// Get quota status
let quota = client.get_quota.await?;
println!;
println!;
Screenshot options
| Option | Type | Description |
|---|---|---|
url |
String |
Target URL to capture (required) |
device |
String |
Device preset (e.g., "Desktop HD", "iPhone 14", "iPad") |
viewport |
ViewportConfig |
Custom viewport dimensions |
format |
ImageFormat |
Output format: Png, Jpeg, Webp, Pdf |
full_page |
bool |
Capture the full scrollable page |
quality |
i32 |
Image quality (1-100, for JPEG/WebP) |
delay |
i32 |
Delay before capture in milliseconds (0-30000) |
wait_for |
String |
CSS selector to wait for |
wait_until |
WaitUntil |
Page load condition (Load, DomContentLoaded, NetworkIdle) |
timeout |
i32 |
Request timeout in milliseconds (1000-60000) |
dark_mode |
bool |
Enable dark mode |
custom_css |
String |
Custom CSS to inject |
hide_selectors |
Vec<String> |
CSS selectors to hide |
selector |
String |
Capture specific element |
block_ads |
bool |
Block advertisements |
block_cookie_banners |
bool |
Block cookie consent banners |
block_level |
BlockLevel |
Ad/tracker blocking level |
Device presets
Common device presets:
| Device | Viewport |
|---|---|
| Desktop HD | 1920x1080 |
| Desktop | 1440x900 |
| Laptop | 1366x768 |
| iPhone 14 | 390x844 |
| iPhone 14 Pro Max | 430x932 |
| iPad | 820x1180 |
| iPad Pro | 1024x1366 |
Error handling
The SDK provides typed errors for robust error handling:
use ;
let client = from_env?;
let request = builder
.url
.build?;
match client.screenshot.await
Retryable errors
The SDK automatically retries transient errors with exponential backoff:
- Rate limit exceeded (429)
- Internal server errors (5xx)
- Network timeouts
- Connection errors
Configure retry behavior:
let client = builder
.api_key
.max_retries
.build?;
License
Apache License 2.0