tessera/lib.rs
1//! # tessera
2// Brand names read fine without markup; keep the prose clean.
3#![allow(clippy::doc_markdown)]
4//!
5//! The official Rust client for [Tessera](https://tesseralytics.dev) —
6//! order-flow-enriched OHLCV, funding-rate, and positioning datasets built
7//! from raw Hyperliquid trade data, delivered as Parquet over a REST API.
8//!
9//! This crate is the Rust mirror of the
10//! [`tessera-api`](https://pypi.org/project/tessera-api/) Python SDK: point it
11//! at a `(dataset, coin, month)` and read straight from object storage into
12//! [Polars](https://pola.rs) or [DuckDB](https://duckdb.org) over presigned
13//! URLs — with predicate/projection pushdown, no temp files.
14//!
15//! ## Choosing a client
16//!
17//! - [`TesseraClient`] — blocking API. Owns a private tokio runtime, so do not
18//! construct it from inside an async runtime.
19//! - [`AsyncTesseraClient`] — `async fn` surface for tokio applications.
20//!
21//! ## Data engines
22//!
23//! - Polars (default feature `polars`): [`TesseraClient::scan`] returns a
24//! `LazyFrame`; [`TesseraClient::read`] collects a `DataFrame`.
25//! - DuckDB (opt-in feature `duckdb`): `TesseraClient::to_duckdb` returns an
26//! in-memory connection exposing a `tessera` view.
27//!
28//! ## Plans
29//!
30//! The free tier covers every coin and all three datasets over the trailing
31//! 30 days, served at month granularity (the current and previous calendar
32//! month). Closed history is sold as one-off bundles; [`TesseraClient::datasets`]
33//! and [`TesseraClient::partitions`] already reflect your entitlement, so the
34//! client needs no plan logic of its own.
35//!
36//! ## Errors
37//!
38//! Every failure raises [`TesseraError`], mirroring the Python exception
39//! taxonomy (`Configuration`, `NotFound`, `PresignExpired`, …).
40//!
41//! ## Example
42//!
43//! ```no_run
44//! # fn main() -> Result<(), tessera::TesseraError> {
45//! let client = tessera::TesseraClient::new(None)?;
46//! // Pick the newest available month rather than a hardcoded one:
47//! // partitions roll on a trailing 30-day window, so fixed dates go stale.
48//! let latest = client
49//! .partitions("gold_ohlcv_1m", Some("BTC"), None)?
50//! .partitions
51//! .pop()
52//! .expect("at least one partition");
53//! let frame = client.read("gold_ohlcv_1m", "BTC", &latest.month, None)?;
54//! println!("{} rows for {}", frame.height(), latest.month);
55//! # Ok::<(), tessera::TesseraError>(())
56//! # }
57//! ```
58
59/// The crate version, as published on crates.io.
60pub const VERSION: &str = env!("CARGO_PKG_VERSION");
61
62mod async_client;
63mod base;
64mod client;
65mod config;
66mod error;
67mod models;
68/// Data-engine plumbing: Parquet readers for Polars and DuckDB.
69///
70/// Most users go through [`TesseraClient::scan`] / [`TesseraClient::read`] /
71/// `TesseraClient::to_duckdb`; the readers are public for advanced
72/// composition over pre-resolved URLs.
73pub mod readers;
74#[cfg(any(feature = "polars", feature = "duckdb"))]
75pub mod resolver;
76
77pub use crate::async_client::AsyncTesseraClient;
78pub use crate::client::TesseraClient;
79pub use crate::config::{API_KEY_ENV_VAR, ClientConfig, DEFAULT_BASE_URL, USER_AGENT};
80pub use crate::error::{TesseraError, error_from_response};
81pub use crate::models::{
82 DatasetSummary, DatasetsResponse, DayDownload, DayDownloadResponse, DownloadBody,
83 DownloadResponse, ErrorBody, IntoCoins, IntoMonths, MonthRange, MonthSpan, Partition,
84 PartitionRef, PartitionsResponse, download_urls,
85};