Expand description
§epochal-api
Rust client for the Epochal API. Its one module today is the Time Portal: web search, web fetch and sandboxes held to a past instant, so nothing published or crawled after it is used.
Each method is one API call. Waiting, polling and retries are left to the caller; for sandboxes
that do all three, use epochal-sandbox.
§Setup
cargo add epochal-api
cargo add tokio --features macros,rt-multi-thread
export EPOCHAL_API_KEY=... # from https://console.epochal.com/keysRequires Rust 1.88 or later. The client reads EPOCHAL_API_KEY, and EPOCHAL_BASE_URL if set
(default https://api.epochal.com); Client::builder().with_api_key(...) and .with_base_url(...)
override them.
§Example
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(2025, 3, 12, 0, 0, 0).unwrap();
let portal = Client::builder().build()?.time_portal(as_of);
let found = portal.search(&SearchRequest::new("fed rate decision")).await?;
for hit in &found.results {
println!("{} {}", hit.title, hit.url);
if let Some(entity) = &hit.entity {
println!(" {}: {:?}", entity.kind, entity.typed());
}
}
let mut read = FetchRequest::new("https://www.federalreserve.gov/");
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(())
}§What’s in it
Client holds the key and the connection pool; each API module is a handle from it.
client.time_portal(as_of) returns a TimePortal held to as_of, whose methods are the time
portal’s calls:
- Web:
search,fetch(a page as markdown, with its metadata) andpage(the archived document itself), each held to the portal’sas_of. A page that could not be read isOk, withstatusPageStatus::Errorand the site’s reason inpage_error. Request and response types are intime_portal::web. - Entities: a
searchresult that is ahttps://world.epochal.com/page carries its entity inresults[i].entity(Noneon every other result), andfetchreturns such a page’s entity inentity.SearchResponse.entitiesis reserved; entities come onresults[i].entity.entity.propertiesis the JSON as sent;entity.typed()reads it into aTypedEntity: one model per public type (organization, person, place, crypto, weather) fromtime_portal::entities, orTypedEntity::Unknownwith the JSON for a type, or aschema_versionof one, this version doesn’t model. Their enums are open: a new value isOther(value). - Sandboxes:
create_sandbox,get_sandbox,list_sandboxes,terminate_sandbox,start_exec,read_exec_output,send_exec_input,stat_file,list_files,read_file,write_fileandremove_file. Types are intime_portal::sandbox.create_sandboxmakes a box held to the portal’sas_of; the other calls name a box by id, and it keeps its own instant. A call that waits, such asget_sandboxwith await, is held for at mostMAX_WAIT(55 s).create_sandboxandstart_execsend anIdempotency-Key: the request’s own, or else a freshidempotency_key(). To retry one without making a second box or running the command twice, set the key once and send it with every attempt. - Errors: every call returns
Error:MissingApiKey,InvalidArgument(refused before any request),Transport,Api(withstatus,kind,message,request_id,retry_after) andDecode. - Newer servers: a search category this version doesn’t name is
Category::Other(name), andSearchRequestandFetchRequesthave anextramap of fields sent as given, so a new search or fetch option needs no new release. - Connections:
ClientandTimePortalare cheap to clone, and clones share one connection pool. Redirects are never followed, so the key never leaves for another host.
chrono is re-exported, so as_of instants need no extra dependency.
License: Apache-2.0.
Re-exports§
pub use chrono;pub use serde_json;
Modules§
- time_
portal /v1/time-portal: the web, and Linux sandboxes, held to a past instant. Every call is a method ofTimePortal, fromClient::time_portal.
Structs§
- Client
- An Epochal API client, from
Client::builder. Each API module is a handle from it, such astime_portal. Cheap to clone; clones share one connection pool. - Client
Builder - Configures a
Client. Anything not set takes its default whenbuildruns.
Enums§
- Error
- A failed request.
Constants§
- MAX_
WAIT - The longest the API holds a call that waits, such as
TimePortal::get_sandboxwith await.