Expand description
§Pxshot
Official Rust SDK for the Pxshot screenshot API.
§Features
- Async-first: Built on
tokioandreqwestfor high-performance async I/O - Strongly typed: Full type safety with serde serialization
- Builder pattern: Ergonomic request construction
- Optional blocking client: Enable with the
blockingfeature
§Quick Start
use pxshot::{Pxshot, ScreenshotRequest, ImageFormat};
#[tokio::main]
async fn main() -> pxshot::Result<()> {
// Create client with your API key
let client = Pxshot::new("px_your_api_key");
// Capture a screenshot as bytes
let response = client
.screenshot(
ScreenshotRequest::builder()
.url("https://example.com")
.format(ImageFormat::Png)
.width(1920)
.height(1080)
.build()?,
)
.await?;
// Get the image bytes
let bytes = response.into_bytes().unwrap();
std::fs::write("screenshot.png", bytes)?;
Ok(())
}§Storing Screenshots
Instead of receiving raw bytes, you can store screenshots and get a URL:
use pxshot::{Pxshot, ScreenshotRequest};
#[tokio::main]
async fn main() -> pxshot::Result<()> {
let client = Pxshot::new("px_your_api_key");
let response = client
.screenshot(
ScreenshotRequest::builder()
.url("https://example.com")
.store(true)
.build()?,
)
.await?;
let stored = response.into_stored().unwrap();
println!("Screenshot URL: {}", stored.url);
println!("Expires at: {}", stored.expires_at);
Ok(())
}§Blocking Client
Enable the blocking feature in your Cargo.toml:
[dependencies]
pxshot = { version = "0.1", features = ["blocking"] }Then use the blocking client:
ⓘ
use pxshot::blocking::Pxshot;
use pxshot::ScreenshotRequest;
fn main() -> pxshot::Result<()> {
let client = Pxshot::new("px_your_api_key");
let response = client.screenshot(
ScreenshotRequest::builder()
.url("https://example.com")
.build()?,
)?;
Ok(())
}§Usage Statistics
Check your API usage:
use pxshot::Pxshot;
#[tokio::main]
async fn main() -> pxshot::Result<()> {
let client = Pxshot::new("px_your_api_key");
let usage = client.usage().await?;
println!("Screenshots this period: {}", usage.screenshots);
println!("Bytes used: {}", usage.bytes);
Ok(())
}Modules§
- blocking
blocking - Blocking client module (requires
blockingfeature).
Structs§
- Pxshot
- Pxshot API client.
- Screenshot
Request - Request to capture a screenshot.
- Screenshot
Request Builder - Builder for
ScreenshotRequest. - Stored
Screenshot - Response when storing a screenshot (store=true).
- Usage
- API usage statistics.
Enums§
- Error
- Errors that can occur when using the Pxshot SDK.
- Image
Format - Image format for screenshots.
- Screenshot
Response - Result of a screenshot request.
- Wait
Until - When to consider the page loaded.
Type Aliases§
- Result
- Result type alias using the Pxshot error type.