Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

Async client for Hugging Face Hub

Implementations§

Source§

impl Client

Source

pub async fn arxiv_paper(&self, req: ArxivPaperReq<'_>) -> Result<ArxivPaperRes>

Get the API equivalent of the Paper page, i.e., metadata like authors, summary, and discussion comments

Endpoint: GET /api/papers/{arxiv_id}

Source

pub async fn arxiv_repos(&self, req: ArxivReposReq<'_>) -> Result<ArxivReposRes>

Get all the models, datasets, and Spaces that refer to a paper

Endpoint: GET /api/arxiv/{arxiv_id}/repos

Source

pub async fn arxiv_daily(&self) -> Result<ArxivDailyRes>

Get the daily papers curated by AK and the community

Endpoint: GET /api/daily_papers

TODO: support filter on date

Source§

impl Client

Source

pub async fn get_collections( &self, req: GetCollectionsReq<'_>, ) -> Result<GetCollectionsRes>

List collections from the Hub, based on some criteria

Endpoint: GET /api/collections

Source

pub async fn get_collection( &self, req: GetCollectionReq<'_>, ) -> Result<GetCollectionRes>

Get information about a collection

Endpoint: GET /api/collections/{namespace}/{slug}-{id}

Source

pub async fn create_collection( &self, req: CreateCollectionReq<'_>, ) -> Result<GetCollectionRes>

Create a new collection on the Hub with a title

Endpoint: POST /api/collections

Source

pub async fn delete_collection( &self, req: DeleteCollectionReq<'_>, ) -> Result<DeleteCollectionRes>

Delete a collection, cannot be restored.

Endpoint: DELETE /api/collections/{namespace}/{slug}-{id}

Source

pub async fn modify_collection( &self, req: ModifyCollectionReq<'_>, ) -> Result<ModifyCollectionRes>

Update the metadata of a collection on the Hub

Endpoint: PATCH /api/collections/{namespace}/{slug}-{id}

Source

pub async fn create_collection_item( &self, req: CreateCollectionItemReq<'_>, ) -> Result<CreateCollectionItemRes>

Add an item to a collection

Endpoint: POST /api/collections/{namespace}/{slug}-{id}/items

Source

pub async fn modify_collection_item( &self, req: ModifyCollectionItemReq<'_>, ) -> Result<ModifyCollectionItemRes>

Update an item in a collection

Endpoint: PATCH /api/collections/{namespace}/{slug}-{id}/items

Source

pub async fn delete_collection_item( &self, req: DeleteCollectionItemReq<'_>, ) -> Result<DeleteCollectionItemRes>

Remove an item from a collection

Endpoint: Delete /api/collections/{namespace}/{slug}-{id}/items

Source§

impl Client

Source

pub async fn get_members(&self, req: GetMembersReq<'_>) -> Result<GetMembersRes>

Get a list of the Organization members.

Endpoint: GET /api/organizations/{organization_name}/members

Source§

impl Client

Source

pub async fn search_model( &self, req: SearchModelReq<'_>, ) -> Result<SearchModelRes>

Get information from all models in the Hub

Endpoint: GET /api/models

Source

pub async fn get_model(&self, req: GetModelReq<'_>) -> Result<GetModelRes>

Get all information for a specific model

Endpoint: GET /api/models/{repo_id} or

Endpoint: GET /api/models/{repo_id}/revision/{revision}

Source

pub async fn get_model_tags(&self) -> Result<GetModelTagsRes>

Gets all the available model tags hosted in the Hub

Endpoint: GET /api/models-tags-by-type

Source

pub async fn search_dataset( &self, req: SearchDatasetReq<'_>, ) -> Result<SearchDatasetRes>

Get information from all datasets in the Hub

Endpoint: GET /api/datasets

Source

pub async fn get_dataset(&self, req: GetDatasetReq<'_>) -> Result<GetDatasetRes>

Get all information for a specific dataset

Endpoint: GET /api/datasets/{repo_id} or

Endpoint: GET /api/datasets/{repo_id}/revision/{revision}

Source

pub async fn get_dataset_tags(&self) -> Result<GetDatasetTagRes>

Gets all the available dataset tags hosted in the Hub

Endpoint: GET /api/datasets-tags-by-type

Source

pub async fn search_space( &self, req: SearchSpaceReq<'_>, ) -> Result<SearchSpaceRes>

Get information from all spaces in the Hub

Endpoint: GET /api/spaces

Source

pub async fn get_space(&self, req: GetSpaceReq<'_>) -> Result<GetSpaceRes>

Get all information for a specific space

Endpoint: GET /api/spaces/{repo_id} or

Endpoint: GET /api/spaces/{repo_id}/revision/{revision}

Source

pub async fn create_repo(&self, req: CreateRepoReq<'_>) -> Result<CreateRepoRes>

Create a repository, model repo by default

Endpoint: POST /api/repos/create

Source

pub async fn delete_repo(&self, req: DeleteRepoReq<'_>) -> Result<()>

Delete a repository, model repo by default

Endpoint: DELETE /api/repos/delete

Source

pub async fn move_repo(&self, req: MoveRepoReq<'_>) -> Result<()>

Move a repository (rename within the same namespace or transfer from user to organization).

Endpoint: POST /api/repos/move

Source

pub async fn get_metrics(&self) -> Result<GetMetricsRes>

Gets all the available metrics in the Hub

Endpoint: GET /api/metrics

Source

pub async fn get_parquet(&self, req: GetParquetReq<'_>) -> Result<GetParquetRes>

Get the list of auto-converted parquet files

Endpoint: GET /api/datasets/{repo_id}/parquet

Endpoint: GET /api/datasets/{repo_id}/parquet/{subset}

Endpoint: GET /api/datasets/{repo_id}/parquet/{subset}/{split}

Source

pub async fn download_parquet( &self, req: DownloadParquetReq<'_>, ) -> impl Stream<Item = Result<Bytes>>

Get the nth shard of the auto-converted parquet files, for a specific subset (also called “config”) and split.

Endpoint: GET /api/datasets/{repo_id}/parquet/{subset}/{split}/{n}.parquet

Source

pub async fn download_parquet_by_url( &self, url: impl AsRef<str>, ) -> impl Stream<Item = Result<Bytes>>

Get the nth shard of the auto-converted parquet files, same as Client::download_parquet

url: full url of parquet file, you can get this from Client::get_parquet, this is an example: https://huggingface.co/api/datasets/DMindAI/DMind_Benchmark/parquet/objective_infrastructure/Infrastructrue/0.parquet

Source§

impl Client

Source

pub async fn get_userinfo(&self) -> Result<GetUserInfoRes>

Get username and organizations the user belongs to

Endpoint: GET /api/whoami-v2

Source§

impl Client

Source

pub fn new(option: ClientOption) -> Result<Self>

Create Client instance with ClientOption

use hugging_face_client::client::Client;
use hugging_face_client::client::ClientOption;
use std::time::Duration;

fn main() {
  let option = ClientOption::new("HUGGING_FACE_TOKEN")
    .timeout(Duration::from_secs(5));
  let client = Client::new(option);
}

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T