Skip to main content

Crate pxshot

Crate pxshot 

Source
Expand description

§Pxshot

Official Rust SDK for the Pxshot screenshot API.

§Features

  • Async-first: Built on tokio and reqwest for high-performance async I/O
  • Strongly typed: Full type safety with serde serialization
  • Builder pattern: Ergonomic request construction
  • Optional blocking client: Enable with the blocking feature

§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§

blockingblocking
Blocking client module (requires blocking feature).

Structs§

Pxshot
Pxshot API client.
ScreenshotRequest
Request to capture a screenshot.
ScreenshotRequestBuilder
Builder for ScreenshotRequest.
StoredScreenshot
Response when storing a screenshot (store=true).
Usage
API usage statistics.

Enums§

Error
Errors that can occur when using the Pxshot SDK.
ImageFormat
Image format for screenshots.
ScreenshotResponse
Result of a screenshot request.
WaitUntil
When to consider the page loaded.

Type Aliases§

Result
Result type alias using the Pxshot error type.