Clients

SDKs

The Epochal SDK is available for Rust and Python. epochal-api is the API client, and epochal-sandbox builds on top of it to run commands and transfer files in sandboxes. Both read EPOCHAL_API_KEY. Rust requires 1.88 or later; Python requires 3.11.4 or later and provides both synchronous and asynchronous clients.

Install

Shell

bash

# Rust
cargo add epochal-api epochal-sandbox
cargo add tokio --features macros,rt-multi-thread

# Python
pip install epochal-api epochal-sandbox

export EPOCHAL_API_KEY="ek_…"
PackageRustPython
epochal-apicrates.io, docs.rsPyPI
epochal-sandboxcrates.io, docs.rsPyPI

The source for both languages is at github.com/epochal-org/epochal.

Search and fetch

use epochal_api::chrono::{TimeZone, Utc};
use epochal_api::time_portal::web::{FetchRequest, PageStatus, SearchRequest};
use epochal_api::Client;

#[tokio::main]
async fn main() -> Result<(), epochal_api::Error> {
    let as_of = Utc.with_ymd_and_hms(2024, 10, 6, 23, 59, 59).unwrap();
    let portal = Client::builder().build()?.time_portal(as_of);

    let found = portal.search(&SearchRequest::new("Nobel Prize 2024 predictions")).await?;
    for hit in &found.results {
        println!("{} {}", hit.title, hit.url);
    }

    let mut read = FetchRequest::new("https://www.nobelprize.org/");
    read.max_characters = Some(2_000);
    let page = portal.fetch(&read).await?;
    match page.status {
        PageStatus::Success => println!("{}", page.content),
        _ => println!("not read: {:?}", page.page_error),
    }
    Ok(())
}

time_portal(as_of) pins all calls on the returned handle to one Accept-Datetime instant. In Python, pass a timezone-aware datetime, an ISO 8601 string, or a YYYY-MM-DD date (interpreted as 23:59:59 UTC that day). AsyncClient exposes the same methods as coroutines.

Sandboxes

use epochal_sandbox::chrono::{TimeZone, Utc};
use epochal_sandbox::{Network, Sandbox, Stream};

#[tokio::main]
async fn main() -> Result<(), epochal_sandbox::Error> {
    let as_of = Utc.with_ymd_and_hms(2024, 10, 6, 23, 59, 59).unwrap();
    let sandbox = Sandbox::time_portal(as_of)
        .with_network(Network::TimePortal)
        .build()
        .await?;

    let out = sandbox.command(["date", "-u"]).output().await?;
    println!("{}", String::from_utf8_lossy(&out.stdout));

    sandbox.files().upload_dir("./src", "/home/epochal/src").await?;
    let run = sandbox
        .command(["python3", "-u", "analyze.py"])
        .with_cwd("/home/epochal/src")
        .start()
        .await?;
    while let Some(chunk) = run.next().await? {
        if chunk.stream == Stream::Stdout {
            print!("{}", String::from_utf8_lossy(&chunk.data));
        }
    }
    sandbox.files().download_dir("/home/epochal/out", "./out").await?;

    sandbox.terminate().await?;
    Ok(())
}

build() waits until the sandbox is live, and exiting the with block terminates it automatically. Sandbox creation and command start requests include an Idempotency-Key so retries do not create duplicate sandboxes or rerun commands.

Next steps

Search

Time Portal search gives ranked results from the time-gated web.

Fetch

Time Portal fetch gives an archived copy of a page from the time-gated web.

Sandbox

A sandbox is a Linux virtual machine whose clock and network are set to an instant.