Skip to main content

unitycatalog_client/
lib.rs

1//! Async Rust client for the Unity Catalog REST API.
2//!
3//! [`UnityCatalogClient`] is the entry point: construct it from a base URL and an
4//! auth token, then reach a resource through the accessor for that resource —
5//! `catalog(name)`, `list_catalogs()`, `tables_client()`, and so on. Each accessor
6//! returns a scoped sub-client or request builder; list builders implement
7//! `IntoFuture` (so you can `.await` them directly) and `into_stream()` for
8//! auto-paginated iteration.
9//!
10//! Two surfaces are hand-written rather than generated from the API spec and have
11//! their own accessors: [`UnityCatalogClient::delta_v1`] for the `/delta/v1` Delta
12//! REST API and [`UnityCatalogClient::temporary_credentials`] for credential
13//! vending with name → UUID resolution.
14//!
15//! ```no_run
16//! use unitycatalog_client::UnityCatalogClient;
17//! use url::Url;
18//!
19//! # async fn run() -> unitycatalog_client::Result<()> {
20//! let client = UnityCatalogClient::new_with_token(
21//!     Url::parse("https://example.com/api/2.1/unity-catalog/").unwrap(),
22//!     "dapi...",
23//! );
24//!
25//! // Fetch one catalog by name.
26//! let catalog = client.catalog("main").get().await?;
27//! # Ok(())
28//! # }
29//! ```
30//!
31//! Fallible calls return [`Result`], whose error type [`Error`] distinguishes UC
32//! API errors ([`UcApiError`]) from Delta error envelopes and offers predicates
33//! like [`Error::is_not_found`] for control flow.
34
35pub use codegen::UnityCatalogClient;
36pub use codegen::agent_skills::AgentSkillClient;
37pub use codegen::agents::AgentClient;
38pub use codegen::catalogs::CatalogClient;
39pub use codegen::credentials::CredentialClient;
40pub use codegen::external_locations::ExternalLocationClient;
41pub use codegen::functions::FunctionClient;
42pub use codegen::policies::PolicyClient;
43pub use codegen::providers::ProviderClient;
44pub use codegen::recipients::RecipientClient;
45pub use codegen::registered_models::RegisteredModelClient;
46pub use codegen::schemas::SchemaClient;
47pub use codegen::shares::ShareClient;
48pub use codegen::staging_tables::StagingTableClient;
49pub use codegen::tables::TableClient;
50pub use codegen::tag_policies::TagPolicyClient;
51pub use codegen::volumes::VolumeClient;
52pub use delta_v1::DeltaV1Client;
53pub use error::*;
54pub use temporary_credentials::*;
55
56pub mod codegen;
57mod delta_v1;
58pub mod error;
59mod temporary_credentials;
60
61/// The HTTP transport the client is built on, selected per target. Native builds
62/// use `olai_http::CloudClient`; `wasm32` builds use `olai_http_wasm::WasmClient`
63/// (the browser Fetch transport). This mirrors the alias the generated code emits
64/// (see `codegen/client.rs`) so the hand-written [`delta_v1`] and
65/// [`temporary_credentials`] surfaces hold the same transport type.
66#[cfg(not(target_arch = "wasm32"))]
67pub(crate) use olai_http::CloudClient as Transport;
68#[cfg(target_arch = "wasm32")]
69pub(crate) use olai_http_wasm::WasmClient as Transport;
70
71impl UnityCatalogClient {
72    /// Ergonomic accessor for the temporary credential vending client.
73    ///
74    /// Wraps the generated low-level client with the hand-written name → UUID resolving helpers
75    /// (`temporary_table_credential`, `temporary_volume_credential`, `temporary_path_credential`).
76    pub fn temporary_credentials(&self) -> TemporaryCredentialClient {
77        TemporaryCredentialClient::new(self.temporary_credentials_client())
78    }
79
80    /// Ergonomic accessor for the hand-written `/delta/v1/` Delta REST API client.
81    ///
82    /// Reuses a generated low-level client's cloud client and base URL (both carry
83    /// the same auth + endpoint), so the Delta v1 client shares the aggregate
84    /// client's configuration without touching generated code.
85    pub fn delta_v1(&self) -> DeltaV1Client {
86        let base = self.tables_client();
87        DeltaV1Client::new(base.client, base.base_url)
88    }
89}