huggingface_hub library

Classes

BlobLfsInfo
BlobSecurityInfo
CardData
Structure containing metadata from a RepoCard.
DatasetCardData
Dataset Card Metadata that is used by Hugging Face Hub when included at the top of your README.md
DatasetInfo
Contains information about a dataset on the Hub. This object is returned by `dataset_info` and `list_datasets`.
EvalResult
Flattened representation of individual evaluation results found in model-index of Model Cards.
ExpandDataset
ExpandModel
ExpandProperty
This allows for type-safe handling of different property enums in a single list.
ExpandSpace
HfApi
Client to interact with the Hugging Face Hub via HTTP.
HfFileMetadata
Data structure containing information about a file versioned on the Hub.
HuggingfaceHub
HuggingfaceHubThrowOnError
Throw on error for only specific HuggingfaceHub initialization errors
InferenceProviderMapping
LastCommitInfo
LocalDownloadFileMetadata
Metadata about a file in the local directory related to a download process.
LocalDownloadFilePaths
Paths to the files related to a download process in a local dir.
ModelCardData
Model Card Metadata that is used by Hugging Face Hub when included at the top of your README.md
ModelInfo
Contains information about a model on the Hub. This object is returned by `model_info` and `list_models`.
RepoFile
Contains information about a file on the Hub.
RepoFileOrFolder
RepoFolder
Contains information about a folder on the Hub.
RepoInfoBase
RepoSibling
Contains basic information about a repo file inside a repo on the Hub.
SafeTensorsInfo
SpaceCardData
Space Card Metadata that is used by Hugging Face Hub when included at the top of your README.md
SpaceInfo
Contains information about a Space on the Hub. This object is returned by `space_info` and `list_spaces`.
SpaceRuntime
Contains information about the current runtime of a Space.
TransformersInfo
XetConnectionInfo
XetFileData

Enums

ExpandDatasetProperty
ExpandModelProperty
ExpandSpaceProperty
SpaceHardware
Enumeration of hardwares available to run your Space on the Hub.
SpaceStage
Enumeration of possible stage of a Space on the Hub.
SpaceStorage
Enumeration of persistent storage available for your Space on the Hub.

Functions

adjustRangeHeader(String? originalRange, int resumeSize) String?
Adjust HTTP Range header to account for resume position.
areSymlinksSupported([String? cacheDir]) Future<bool>
Return whether the symlinks are supported on the machine.
buildHfHeaders({dynamic token, String? libraryName, String? libraryVersion, dynamic userAgent, Map<String, String>? headers}) Future<Map<String, String>>
Build headers dictionary to send in a HF Hub call.
commonPath(List<String> paths) String?
Finds the longest common path from a list of absolute paths.
copyFle(String src, String dst, {bool recursive = false}) Future<File>
Copy a file from src path to dst path. Takes into account where the src is a symlink as Dart is not able to copy symlinks on Windows due to a bug.
filterRepoObjects<T>({required Iterable<T> items, List<String>? allowPatterns, List<String>? ignorePatterns, String key(T)?}) Iterable<T>
Filter repo objects based on an allowlist and a denylist.
fnmatchToRegExp(String pattern) RegExp
Converts a shell-style wildcard pattern into a valid RegExp pattern.
generateRandomString([int length = 8, String characters = 'abcdefghijklmnopqrstuvwxyz0123456789_']) String
Generates a random string of a given length from a set of characters.
getDartVersion() String
getHfFileMetadata({required String url, dynamic token, Map? proxies, double? timeout, String? libraryName, String? libraryVersion, dynamic userAgent, Map<String, String>? headers, String? endpoint}) Future<HfFileMetadata>
Fetch metadata of a file versioned on the Hub for a given url.
getHfHubVersion() String
getLocalDownloadPaths({required String localDir, required String filename}) Future<LocalDownloadFilePaths>
Compute paths to the files related to a download process.
getSession() → Dio
Get a requests.Session object, using the session factory from the user.
getToken() Future<String?>
Get token if user is logged in.
getTokenToSend(dynamic token) Future<String?>
Select the token to send from either token or the cache.
getUserHomePath() String
Returns the path to the user's home directory.
hfHubDownload({required String repoId, required String filename, String? subfolder, String? repoType, String? revision, String? libraryName, String? libraryVersion, String? cacheDir, String? localDir, dynamic userAgent, bool forceDownload = false, Map<String, String>? proxies, double etagTimeout = constants.DEFAULT_ETAG_TIMEOUT, dynamic token, bool localFilesOnly = false, Map<String, String>? headers, String? endpoint}) Future<String>
Download a given file if it's not already present in the local cache.
hfHubUrl(String repoId, String filename, {String? subfolder, String? repoType, String? revision, String? endpoint}) String
Construct the URL of a file from the given information.
hfRaiseForStatus(Response response, void raiseForStatus(), [String? endpointName]) → void
Internal version of response.raise_for_status() that will refine a potential HTTPError. Raised exception will be an instance of HfHubHTTPError.
httpBackoff({required String method, required String url, int maxRetries = 5, double baseWaitTime = 1, double maxWaitTime = 8, List<DioExceptionType> retryOnExceptions = const [DioExceptionType.connectionTimeout, DioExceptionType.connectionError], List<int> retryOnStatusCodes = const [503], Map<String, dynamic> kwargs = const {}, Options? dioOptions}) Future<(Response, void Function())>
Wrapper around requests to retry calls on an endpoint, with exponential backoff.
httpGet(String url, RandomAccessFile tempFile, {Map? proxies, int resumeSize = 0, Map<String, dynamic>? headers, int? expectedSize, String? displayedFilename, int nbRetries = 5}) Future<void>
Download a remote file. Do not gobble up errors, and will return errors tailored to the Hugging Face Hub.
isHfTransferAvailable() bool
isPackageAvailable(String packageName) bool
TODO: This isn't really a thing in Dart...
isXetAvailable() bool
modelIndexToEvalResults(List<Map<String, dynamic>> modelIndex) → (String, List<EvalResult>)
Takes in a model index and returns the model name and a list of huggingface_hub.EvalResult objects.
moveFile(String src, String dst) Future<File>
Move a file from src path to dst path
paginate({required String path, required Map<String, dynamic> params, required Map<String, dynamic> headers}) Stream<Map<String, dynamic>>
Fetch a list of models/datasets/spaces and paginate through results.
parseLinkHeader(String? headerValue) Map<String, String>
A helper function to parse an HTTP Link header.
parseXetConnectionInfoFromHeaders(Headers headers) XetConnectionInfo?
Parse XET connection info from the HTTP headers or return None if not found. Args: headers (Dict): HTTP headers to extract the XET metadata from. Returns: XetConnectionInfo or None: The information needed to connect to the XET storage service. Returns None if the headers do not contain the XET connection info.
parseXetFileDataFromResponse(Response? response, [String? endpoint]) XetFileData?
Parse XET file metadata from an HTTP response.
raiseForStatusDioWrapper(Future<Response> requestFn()) Future<(Response, void Function())>
In python the requests package allows you to raise the error at a later point. This helper function helps with that. Probably should be more robust...
readDownloadMetadata({required String localDir, required String filename}) Future<LocalDownloadFileMetadata?>
Read metadata about a file in the local directory related to a download process.
refreshXetConnectionInfo({required XetFileData fileData, required Map<String, String> headers}) Future<XetConnectionInfo>
Utilizes the information in the parsed metadata to request the Hub xet connection information. This includes the access token, expiration, and XET service URL. Args: file_data: (XetFileData): The file data needed to refresh the xet connection information. headers (Dict[str, str]): Headers to use for the request, including authorization headers and user agent. Returns: XetConnectionInfo: The connection information needed to make the request to the xet storage service. Raises: `~utils.HfHubHTTPError` If the Hub API returned an error. ValueError If the Hub API response is improperly formatted.
repoFolderName({required String repoId, required String repoType}) String
Return a serialized version of a hf.co repo name and type, safe for disk storage as a single non-nested folder.
resetSessions() → void
Reset the cache of sessions.
snapshotDownload({required String repoId, String? repoType, String? revision, String? cacheDir, String? localDir, String? libraryName, String? libraryVersion, dynamic userAgent, Map<String, String>? proxies, double etagTimeout = constants.DEFAULT_ETAG_TIMEOUT, bool forceDownload = false, dynamic token, bool localFilesOnly = false, List<String>? allowPatterns, List<String>? ignorePatterns, int maxWorkers = 8, Map<String, String>? headers, String? endpoint}) Future<String>
Download repo files.
SoftTemporaryDirectory<T>(String dir, Future<T> fn(Directory)) Future<T>
Create a temporary directory and safely delete it
tryToLoadFromCache({required String repoId, required String filename, String? cacheDir, String? revision, String? repoType}) Future<Object?>
Explores the cache to return the latest cached file for a given revision if found.
unixTimestamp([DateTime? timestamp]) double
Ge the unix timestamp which is equivalent to python's time.time(). Returns seconds since epoch e.g. "1753339377.418567".
WeakFileLock<T>(String path, Future<T> underLock()) Future<T>
Create a weak file lock for the given file
writeDownloadMetadata({required String localDir, required String filename, required String commitHash, required String etag}) Future<void>
Write metadata about a file in the local directory related to a download process.
xetGet({required String incompletePath, required XetFileData xetFileData, required Map<String, String> headers, int? expectedSize, String? displayedFilename}) Future<void>
Download a file using Xet storage service.

Exceptions / Errors

BadRequestError
Raised by hf_raise_for_status when the server returns a HTTP 400 error.
DisabledRepoError
Raised when trying to access a repository that has been disabled by its author.
EntryNotFoundError
Raised when trying to access a hf.co URL with a valid repository and revision but an invalid filename.
FileMetadataError
Error triggered when the metadata of a file on the Hub cannot be retrieved (missing ETag or commit_hash).
GatedRepoError
Raised when trying to access a gated repository for which the user is not on the authorized list.
HfHubHTTPError
HTTPError to inherit from for any custom HTTP Error raised in HF Hub.
LocalEntryNotFoundError
Raised when trying to access a file or snapshot that is not on the disk when network is disabled or unavailable (connection issue). The entry may exist on the Hub.
LocalTokenNotFoundError
Raised if local token is required but not found.
OfflineModeIsEnabled
Raised when a request is made but HF_HUB_OFFLINE=1 is set as environment variable.
RepositoryNotFoundError
Raised when trying to access a hf.co URL with an invalid repository name, or with a private repo name the user does not have access to.
RevisionNotFoundError
Raised when trying to access a hf.co URL with a valid repository but an invalid revision.