English
Content on This Page

Upload APIs

upload_file

Upload a file. The following is an example:

python
from openmind_hub import upload_file

upload_file(
    path_or_fileobj="demo/test.txt",
    path_in_repo="test.txt",
    repo_id="owner/repo",
    token=None,
    revision="main",
    commit_message="upload file",
    commit_description=None,
)
  • path_or_fileobj (str, Path, bytes, or BinaryIO): path or object of the file to be uploaded.
  • path_in_repo (str): path for uploading files to the repository.
  • repo_id (str): target repository, in the format of username/repository name. For the username and repository name, letters, digits, dots (.), underscores (_), and hyphens (-) are allowed.
  • token (str, optional): access token that has the write permission on the target repository. This parameter is required when this method is used separately.
  • revision (str, optional): branch to be uploaded. Letters, digits, underscores (_), and hyphens (-) are allowed. The default value is None.
  • commit_message (str, optional): commit message of the upload. The default value is Upload {path_in_repo} with openMind hub.
  • commit_description (str, optional): description of this commit.
  • kwargs: required only for compatibility with third-party components.

upload_folder

Upload files in a directory. The following is an example:

python
from openmind_hub import upload_folder

upload_folder(
    repo_id="username/my-cool-space",
    folder_path="demo/local_folder",
    path_in_repo="",
    commit_message="upload folder",
    commit_description=None,
    token="xxxx",
    revision=None,
    allow_patterns="*.bin, *.py",
    ignore_patterns="*.log",
    num_threads=5,
)
  • repo_id (str): target repository, in the format of username/repository name. For the username and repository name, letters, digits, dots (.), underscores (_), and hyphens (-) are allowed.
  • folder_path (str or Path): path of the directory to be uploaded. The uploaded content does not contain the directory itself. Supports character string or path, for example, "demo/folder" or Path("demo/folder").
  • path_in_repo (str, optional): path for uploading files to the repository, which cannot end with a backslash (). By default, the path is an empty string, indicating the root directory of the repository.
  • commit_message (str, optional): commit message of the upload. The default message is Upload folder using openMind hub.
  • commit_description (str, optional): description of this commit.
  • token (str, optional): access token that has the write permission on the target repository. This parameter is required when this method is used separately.
  • revision (str, optional): branch to be uploaded. Letters, digits, underscores (_), and hyphens (-) are allowed. The default value is None.
  • allow_patterns (List[str] or str, optional): only certain types of files can be uploaded. For example, allow_patterns=["*.bin, *.py"] indicates that only .bin and .py files can be uploaded.
  • ignore_patterns (List[str] or str, optional): Ignore the upload of a certain type of files. For example, ignore_patterns="*.log" indicates that all log files are ignored.
  • num_threads (int, optional): number of threads used for uploading. The default value is 5.
  • kwargs: required only for compatibility with third-party components.

create_commit

Upload or delete files. The following is an example:

python
from openmind_hub import create_commit, CommitOperationAdd, CommitOperationDelete

operations = [
    CommitOperationAdd(path_in_repo="LICENSE.md", path_or_fileobj="~/repo/LICENSE.md"),
    CommitOperationAdd(path_in_repo="weights.h5", path_or_fileobj="~/repo/weights-final.h5"),
    CommitOperationDelete(path_in_repo="main.py")
]
create_commit(
    repo_id="owner/repo",
    operations=operations,
    commit_message="create commit",
    commit_description=None,
    token=None,
    revision=None,
    num_threads=5,
)
  • repo_id (str): target repository, in the format of username/repository name. For the username and repository name, letters, digits, dots (.), underscores (_), and hyphens (-) are allowed.
  • operations (Iterable[CommitOperation]): list of the CommitOperationAdd and CommitOperationDelete classes.
  • commit_message (str): commit message of the upload.
  • commit_description (str, optional): description of this commit.
  • token (str, optional): access token that has the write permission on the target repository. This parameter is required when this method is used separately.
  • revision (str, optional): branch to be uploaded. Letters, digits, underscores (_), and hyphens (-) are allowed. The default value is None.
  • num_threads (int, optional): number of threads used for uploading. The default value is 5.
  • kwargs: required only for compatibility with third-party components.