The official Python client to connect with ModelScope Hub.
Python
14
232 commits
updated Sep 21, 2026
The official Python SDK & CLI for ModelScope Hub — download, upload, and manage AI assets from one unified interface.
modelscope-hub connects your code to the ModelScope ecosystem — models, datasets, Studio spaces, skills, and MCP servers — through a single HubApi class or the ms-hub CLI.
modelscope training framework, Studio deployment platform, and MCP server infrastructurev0.4.0 (2026-09-01)
HubApi, ms-hub agent-idp); Studio lists, variables and configuration options; hosted MCP discovery; protected visibility and runtime metadata; read-only tokens can log in and rejected writes name the required tier. Agent private JWKs are only written to an explicitly requested owner-only file.v0.3.1 (2026-09-01)
whoami and legacy responses normalise pre-production field namesv0.3.0 (2026-08-19)
modelscope, ms, modelscope-hub, ms-hub), adds HubApi.get_current_username(), and supports both agent visibility wire formatsrepo/files listings are re-enumerated when the server silently truncates resultsv0.2.0 (2026-08-01)
HubApi.login() now raises NetworkError / ServerError / RequestTimeoutError for non-authentication failures instead of always raising AuthenticationError — widen except AuthenticationError to HubError if you catch any login failure--endpoint modelscope.ai)--endpoint when the token is valid there; --verbose prints the full error cause chainv0.1.9 (2026-07-31)
mcp deploy call-shape assertion and the parse_timestamp timezone-normalization contractms-hub mcp deploy prints the operational URL after deployment; new --auth-check and repeatable --env KEY=VALUE options; --transport-type now validates against sse/streamable_httpcitest workflow — mock-mode test suite (no credentials/network, mirrors distro build sandboxes) on Python 3.10/3.12/3.14 plus ruff/mypy hard gates; releases now require a green test gate before publishing; added a pre-commit configv0.1.8 (2026-07-21)
ms-hub agent raw file transfer (download/upload/list) for remote agent repos; visibility support for agent hub; cache checksum verification (ms-hub cache verify)progress_callbacks through HubApi.download_repo so custom download-progress callbacks work end-to-end; harden legacy (pre-1.38) cache auto-detection (reuse existing {cache}/models/... and default {cache}/hub/models/... layouts); normal (non-LFS) file uploadmodelscope-hub / ms-hub to avoid a file conflict with the modelscope package (e.g. FreeBSD pkg)v0.1.7 (2026-07-07)
snapshot_download cache path with the CLI; add legacy cache fallback--inter-regions CLI arg); cache the region probev0.1.6 (2026-07-03)
v0.1.5 (2026-06-30)
v0.1.4 (2026-06-26)
gated_mode parameter for create_repo; ms-hub create --gated/--no-gated flagscreate_repo extra-kwargs whitelist + type validation; correct visibility mapping (private bool is authoritative)v0.1.3 (2026-06-23)
AlreadyExistsError (E3026) and fix the exist_ok mechanism; align list_repos/RepoInfo with the OpenAPI response formatclear-cache supports all cache layouts (standard/flat/legacy); add last_modified mapping and to_dict() for RepoInfo/PagedResultv0.1.2 (2026-06-23)
list_datasets/get_dataset return format and align parametersv0.1.1 (2026-06-22)
v0.1.0 (2026-06-18)
{cache_dir}/{owner}/{name}/ layoutstr and Path config values)v0.0.9 (2026-06-12)
get_model support revision; expanded param passthrough for repo/model opsparse_timestamp robust timezone conversion for ISO 8601, floats, millisecondsv0.0.8 (2026-06-10)
ms-hub list --all auto-pagination; ms-hub create --skill-file zip upload; ms-hub list --envs--disable-tqdm for folder uploadMODELSCOPE_DOMAIN → MODELSCOPE_ENDPOINTv0.0.5 (2026-06-05)
list_repos pagination and dataset visibility issuesv0.0.4 (2026-06-05)
ms-hub create/info/list/delete)~/.modelscope/credentials/pip install modelscope-hub
Requires Python 3.10+. Lightweight — only requests, tqdm, filelock, urllib3.
This package installs every ModelScope console script, and all four are the same program — pick whichever reads best in your shell:
| Command | Use it for |
|---|---|
modelscope | the primary, brand-level command |
ms | short form of modelscope |
modelscope-hub | explicit hub-only invocation |
ms-hub | short form of modelscope-hub |
Owning all four in one distribution is deliberate: when the umbrella
modelscope SDK also declared
modelscope / ms, installing or upgrading either package could overwrite or
delete the other's scripts and leave you with no CLI at all. OS packagers (such
as FreeBSD pkg) likewise refuse to let two ports own the same path. The SDK now
contributes its extra commands as plugins instead.
So modelscope and ms work on a hub-only install too. Commands that belong to
the full SDK (pipeline, server, studio, modelcard, …) appear once you
also pip install modelscope; until then --help says so. The two *-hub
aliases always report just this package, which is handy for scripts that must
pin the lightweight client:
ms-hub --version # modelscope-hub X.Y.Z
modelscope --version # modelscope A.B.C (modelscope-hub X.Y.Z)
ms-hub login
# or pass a token directly
ms-hub login --token $MODELSCOPE_API_TOKEN
Get your token at modelscope.cn/my/access/token or modelscope.ai/my/access/token.
from modelscope_hub import HubApi
api = HubApi(token="your-token")
user = api.whoami()
print(user.username)
# Full snapshot
ms-hub download Qwen/Qwen3-0.6B
# Single file
ms-hub download Qwen/Qwen3-0.6B config.json
# With filters
ms-hub download Qwen/Qwen3-0.6B --include "*.safetensors" --exclude "*.bin"
# Directly into a local directory (bypasses cache)
ms-hub download Qwen/Qwen3-0.6B --local-dir ./my-model
path = api.download_file("Qwen/Qwen3-0.6B", "model", "config.json")
snapshot = api.download_repo(
"Qwen/Qwen3-0.6B", "model",
allow_patterns=["*.safetensors", "*.json"],
max_workers=8,
)
# Offline mode — return cached path without network access
path = api.download_file("Qwen/Qwen3-0.6B", "model", "config.json", local_files_only=True)
ms-hub upload my-org/my-model ./weights.safetensors
ms-hub upload my-org/my-model ./output --repo-type model --commit-message "add weights"
api.upload_file("my-org/my-model", "model", "./weights.safetensors", "weights.safetensors")
api.upload_folder("my-org/my-model", "model", "./output", path_in_repo="")
ms-hub create my-org/my-model --repo-type model --visibility private
api.create_repo("my-org/my-model", "model", visibility="private", license="apache-2.0")
ms-hub deploy my-org/chat-demo --repo-type studio
ms-hub logs my-org/chat-demo --log-type run
ms-hub stop my-org/chat-demo --repo-type studio
api.deploy_repo("my-org/chat-demo", "studio")
api.get_repo_logs("my-org/chat-demo", log_type="run")
api.stop_repo("my-org/chat-demo", "studio")
The CLI is available as both ms-hub and modelscope-hub.
Global options (placed before or after the subcommand):
| Option | Description |
|---|---|
--token TOKEN | API token (overrides env and persisted token) |
--endpoint URL | API endpoint (default: https://modelscope.cn) |
-v, --verbose | Enable DEBUG logging (global only) |
-V, --version | Print version and exit (global only) |
--tokenand--endpointcan be placed either before or after the subcommand:ms-hub --token xxx download ...andms-hub download ... --token xxxare equivalent.
ms-hub loginAuthenticate and persist your token locally.
ms-hub login # interactive prompt
ms-hub login --token $MY_TOKEN # non-interactive
| Option | Description |
|---|---|
--token TOKEN | API token; prompted interactively if omitted |
Tokens are issued with one of three permission levels, set when you create the token at modelscope.cn/my/myaccesstoken:
| Level | Can do |
|---|---|
read | Browse and download; list your Studios, secrets and variables |
write | Everything above, plus create/upload/deploy and change settings |
admin | Everything above, plus administrative operations |
What this means in practice:
ms-hub login succeeds and prints a warning
that git and session credentials were not issued, so pushes and uploads will
need a write token. Downloads and browsing work normally.[E3002] Permission denied and a suggestion naming the level the
operation requires, rather than leaving you to guess.PermissionDeniedError and
QuotaExceededError (the latter is never retried, since retrying an exhausted
quota only delays the error).The SDK cannot tell you which level your token has: the API does not report it. Check the token settings page if you are unsure.
ms-hub whoamiShow the user associated with the current token.
ms-hub whoami
ms-hub whoami --token $MY_TOKEN # check a specific token without logging in
ms-hub downloadDownload a single file or a full repository snapshot.
ms-hub download Qwen/Qwen3-0.6B # full snapshot
ms-hub download Qwen/Qwen3-0.6B config.json # single file
ms-hub download Qwen/Qwen3-0.6B --include "*.safetensors" # filter by glob
ms-hub download Qwen/Qwen3-0.6B --local-dir ./out --max-workers 8 # direct download
ms-hub download my-org/my-data --repo-type dataset --revision v2 # dataset at tag
| Argument / Option | Required | Description |
|---|---|---|
repo_id | yes | Repository identifier (owner/name) |
files... | no | Specific file paths; omit for full snapshot |
--repo-type {model,dataset} | no | Default: model |
--revision REV | no | Branch, tag, or commit hash (default: master) |
--local-dir DIR | no | Download directly here (bypasses cache layout) |
--cache-dir DIR | no | Override default cache directory |
--include GLOB... | no | Only download matching files; repeatable |
--exclude GLOB... | no | Skip matching files; repeatable |
--max-workers N | no | Parallel download threads (default: 4) |
--force | no | Re-download even if cached |
# Download multiple specific files at once
ms-hub download Qwen/Qwen3-0.6B config.json tokenizer.json generation_config.json
# Download only safetensors, skip GGUF and bin weights
ms-hub download Qwen/Qwen3-0.6B --include "*.safetensors" --exclude "*.bin" "*.gguf"
# Download a dataset at a specific tag into a local directory
ms-hub download my-org/my-data --repo-type dataset --revision v2 --local-dir ./data
# Use a custom cache directory and 8 parallel threads
ms-hub download Qwen/Qwen3-0.6B --cache-dir /data/hub-cache --max-workers 8
# Force re-download even if already cached
ms-hub download Qwen/Qwen3-0.6B config.json --force
# Download all skills from a collection (legacy flag)
ms-hub download --collection my-org/skill-collection
# Enable parallel range download for large files (env var)
MODELSCOPE_DOWNLOAD_PARALLELS=4 ms-hub download Qwen/Qwen3-0.6B
# Use the modelscope.ai endpoint (global option, before subcommand)
ms-hub --endpoint https://modelscope.ai download Qwen/Qwen3-0.6B
ms-hub uploadUpload a file or folder to a repository.
ms-hub upload my-org/my-model ./weights.safetensors # single file
ms-hub upload my-org/my-model ./output models/ --repo-type model # folder → subdir
ms-hub upload my-org/my-model . --include "*.py" --commit-message "code" # filtered folder
| Argument / Option | Required | Description |
|---|---|---|
repo_id | yes | Repository identifier |
local_path | no | Local file or folder (default: inferred from repo name) |
path_in_repo | no | Destination path inside the repo |
--repo-type {model,dataset} | no | Default: model |
--revision REV | no | Target branch (default: master) |
--commit-message MSG | no | Commit message |
--commit-description DESC | no | Extended commit description |
--include GLOB... | no | Include filter for folder mode; repeatable |
--exclude GLOB... | no | Exclude filter for folder mode; repeatable |
--max-workers N | no | Parallel upload threads |
--use-cache / --no-cache | no | Enable/disable resumable upload cache (default: on) |
--disable-tqdm | no | Disable progress bars |
# Upload a single file with a custom commit message
ms-hub upload my-org/my-model ./weights.safetensors --commit-message "add fp16 weights"
# Upload a folder into a subdirectory of the repo
ms-hub upload my-org/my-model ./output models/ --repo-type model
# Upload only Python files from the current directory
ms-hub upload my-org/my-model . --include "*.py" --commit-message "update code"
# Upload only safetensors, skip checkpoints
ms-hub upload my-org/my-model ./output --include "*.safetensors" --exclude "*.ckpt" "*.bin"
# Upload to a dataset repo on a specific branch
ms-hub upload my-org/my-data ./data --repo-type dataset --revision dev
# Upload with extended commit description
ms-hub upload my-org/my-model ./weights.safetensors \
--commit-message "v2 weights" \
--commit-description "Retrained with extended dataset, 3 epochs, lr=2e-5"
# Resumable upload: interrupted uploads resume automatically via cache
ms-hub upload my-org/my-model ./large-folder
# If interrupted, just re-run the same command — already uploaded files are skipped
# Disable upload cache (no resume, fresh upload every time)
ms-hub upload my-org/my-model ./output --no-cache
# Disable progress bars (useful for CI/CD pipelines)
ms-hub upload my-org/my-model ./output --disable-tqdm
ms-hub create / ms-hub info / ms-hub list / ms-hub deleteRepository management.
ms-hub create my-org/my-model --repo-type model --visibility private
ms-hub create my-org/demo --repo-type studio --sdk-type gradio
ms-hub info my-org/my-model --repo-type model
ms-hub list --repo-type model --owner my-org --page-size 20
ms-hub list --repo-type studio --owner my-org
ms-hub delete my-org/my-model --repo-type model --yes
Deprecation notice:
delete_repo/ms-hub deleteemits aDeprecationWarning— programmatic repo deletion is restricted for security reasons and will be restored once token-scoped auth is available. Use the web console to delete repos.
delete_filesrequires cookie-based session auth; API tokens may receive a 401 error.
ms-hub create options| Argument / Option | Required | Description |
|---|---|---|
repo_id | yes | Repository identifier |
--repo-type | yes | model, dataset, studio, or skill |
--visibility | no | public, private or internal. For Studios also protected (app public, code repository hidden) |
--license | no | SPDX license identifier (e.g. apache-2.0) |
--chinese-name | no | Display name in Chinese |
--description | no | Repository description |
--exist-ok | no | No error if repository already exists |
--sdk-type | no | Studio SDK: gradio, streamlit, docker, static |
--sdk-version | no | Studio SDK version |
--base-image | no | Studio base Docker image |
--cover-image | no | Studio cover image URL |
--hardware | no | Studio hardware spec |
ms-hub deploy / ms-hub stop / ms-hub logs / ms-hub settingsManage Studio and MCP deployments.
ms-hub deploy my-org/chat-demo --repo-type studio
ms-hub logs my-org/chat-demo --log-type run --keyword ERROR --page-size 50
ms-hub settings my-org/chat-demo cpu=4 memory=8192
ms-hub stop my-org/chat-demo --repo-type studio
| Command | --repo-type | Key Options |
|---|---|---|
ms-hub deploy <repo_id> | {studio,mcp} (default: studio) | — |
ms-hub stop <repo_id> | {studio,mcp} (default: studio) | — |
ms-hub logs <repo_id> | {studio} only | --log-type {run,build}, --keyword, --page, --page-size |
ms-hub settings <repo_id> key=val... | {studio,skill} (default: studio) | Key-value pairs passed to backend |
Note:
ms-hub logsonly supports Studio spaces. MCP server logs are not available via this command.ms-hub settingssupports Studio and Skill repos; for MCP servers usems-hub mcp deploywith configuration payload.
ms-hub secret / ms-hub studio variableManage a Studio's environment variables. Two commands, because the disclosure differs: a secret's value is never returned by the API, a variable's value is publicly visible.
# Secrets — values are write-only
ms-hub secret add my-org/demo API_KEY sk-xxx
ms-hub secret list my-org/demo
ms-hub secret update my-org/demo API_KEY sk-new
ms-hub secret delete my-org/demo API_KEY --yes
# Plaintext variables — values are readable by anyone
ms-hub studio variable add my-org/demo MODEL_NAME Qwen2.5-7B
ms-hub studio variable list my-org/demo
ms-hub studio variable update my-org/demo MODEL_NAME Qwen2.5-14B
ms-hub studio variable delete my-org/demo MODEL_NAME --yes
| Subcommand | Arguments | Description |
|---|---|---|
add | repo_id key value | Add a new entry |
list | repo_id | List entries (secret shows keys only; variable shows keys and values) |
update | repo_id key value | Update a value |
delete | repo_id key [--yes] | Delete an entry |
ms-hub secret accepts --repo-type (default: studio, currently the only supported type).
Put anything sensitive in a secret. A plaintext variable's value is public.
ms-hub studioBrowse Studio spaces and the runtime resources they can be configured with.
# Browse
ms-hub studio list --search chat --sort likes --page-size 20
ms-hub studio list --owner my-org --status all
ms-hub studio list --mcp-support --hardware-type xgpu
# Discover valid values for --hardware / --base-image / --sdk-version
ms-hub studio hardware --sdk-type gradio
ms-hub studio hardware --studio my-org/demo
ms-hub studio base-images
ms-hub studio sdk-versions --sdk-type gradio
# Runtime management (also available as the top-level deploy/stop/logs/settings)
ms-hub studio deploy my-org/demo
ms-hub studio logs my-org/demo --type build
ms-hub studio settings my-org/demo --visibility protected
| Subcommand | Arguments | Key Options |
|---|---|---|
list | — | --search, --owner, --sort {default,last_modified,view_num,likes}, --status {running,all}, --mcp-support/--no-mcp-support, --hardware-type {xgpu,amd}, --page, --page-size |
hardware | — | --sdk-type, --studio owner/name |
base-images | — | — |
sdk-versions | — | --sdk-type (default gradio; only gradio publishes versions) |
deploy / stop | studio_id | — |
logs | studio_id | --type {run,build}, --keyword, --page, --page-size (max 500) |
settings | studio_id [key=val...] | --display-name, --description, --license, --cover-image, --sdk-type, --sdk-version, --base-image, --hardware, --visibility, --private/--public |
secret | see above | — |
variable | see above | — |
--visibility accepts three values: public (code and app public), protected
(app public, code repository hidden) and private. --private / --public
remain as shorthands.
Paid hardware tiers are selected as --hardware paid/<instance_type>; run
ms-hub studio hardware to see the available identifiers.
--status defaults to all whenever --owner is given, so listing your own
spaces includes stopped ones. Without --owner the server's own default applies
(running spaces only).
ms-hub mcpManage MCP (Model Context Protocol) servers.
ms-hub mcp list --search weather --page-size 10
ms-hub mcp list --hosted # only your own hosted servers, with live URLs
ms-hub mcp info my-org/weather-mcp
ms-hub mcp deploy my-org/weather-mcp
ms-hub mcp undeploy my-org/weather-mcp
| Subcommand | Arguments | Key Options |
|---|---|---|
list | — | --search, --hosted, --page, --page-size |
info | server_id | — |
deploy | server_id | --transport-type, --expiration-minutes, --auth-check, --env KEY=VALUE |
undeploy | server_id | — |
--hosted lists the servers you currently have hosted along with their
operational_urls. It takes no search or paging options, because the underlying
endpoint accepts none.
Discovery is capped at
page * page_size <= 100by the service.
ms-hub cacheInspect and clean the local download cache.
ms-hub cache scan
ms-hub cache scan --cache-dir /data/cache
ms-hub cache verify Qwen/Qwen3-0.6B
ms-hub cache verify Qwen/Qwen3-0.6B --local-dir ./Qwen3-0.6B
ms-hub cache clear --repo-type model --yes
ms-hub cache clear --repo-id my-org/old-model --repo-type model --yes
| Subcommand | Key Options |
|---|---|
scan | --cache-dir DIR |
verify REPO_ID | --repo-type, --revision, --cache-dir, --local-dir, --fail-on-missing-files, --fail-on-extra-files |
clear | --repo-type, --repo-id, --cache-dir, --yes |
ms-hub agentRemote agent repositories: raw file transfer (download, upload, list) and plugin-driven install.
ms-hub agent download -r user/my-agent --local-dir ./my-agent # download raw files
ms-hub agent upload -r user/my-agent --local-dir ./my-agent # upload raw
ms-hub agent install -r user/my-agent # install into the framework
download / upload / list transfer files as-is, with no framework awareness.
install is different: it fetches an official plugin and hands the agent id to it, leaving every framework decision to the plugin. See ms-hub agent install for the details and the security model.
Framework-aware operations (cross-framework
convert,watch/bidirectional sync,status,backups,restore,stop) live in modelscope-agent — usems-agent agent ...instead. For example, to download and convert in one step:ms-agent agent download -f qoder -r user/my-agent --target-framework qwenpaw.
ms-hub agent downloadDownload all files of a remote agent repository to a local directory (raw, no conversion).
ms-hub agent download -r user/my-agent
ms-hub agent download -r user/my-agent --local-dir ./my-agent --revision master
| Option | Required | Description |
|---|---|---|
-r, --repo REPO | yes | Remote repo identifier (owner/name) |
--local-dir DIR | no | Destination directory (default: ./<repo-name> under CWD) |
--revision REV | no | Repository revision (default: master) |
ms-hub agent uploadUpload files from a local path (file or directory) to a remote agent repository (raw, no conversion). Creates the repo if it does not exist.
ms-hub agent upload -r user/my-agent --local-dir ./my-agent
ms-hub agent upload -r user/my-agent --local-dir ./my-agent --dry-run
| Option | Required | Description |
|---|---|---|
-r, --repo REPO | yes | Remote repo identifier (owner/name) |
--local-dir DIR | no | Source path (file or directory) to upload (default: CWD) |
--revision REV | no | Repository revision (default: master) |
--dry-run | no | List files that would be uploaded without uploading |
ms-hub agent installDownload an agent and hand it to its framework plugin. A plugin with an install entry point places the agent into the framework's workspace; one that only transports bytes writes the repository's files into a destination directory and leaves placement to whatever runs next. The command reports which happened (Installed … vs Fetched …).
ms-hub agent install -r user/my-agent
| Option | Required | Description |
|---|---|---|
-r, --repo REPO | yes | Agent repository to install (owner/name) |
--plugin-revision REV | no | Plugin revision (default: master; pin a tag for reproducible installs) |
-n, --name NAME | no | Sub-agent name, passed through to the plugin |
--framework FW | no | Override the plugin's framework detection |
--local-dir DIR | no | Where the agent repository is downloaded, not where it is installed. Omitted, downloads go to $MODELSCOPE_CACHE/agent/agent-staging/<owner>--<name>-<timestamp>/ and are cleaned up on success |
--dry-run | no | Ask the plugin to report instead of change anything. The plugin is still downloaded, imported and run — only its writes are suppressed |
-y, --yes / --force / -q, --quiet | no | Passed through to the plugin |
Exit codes: 0 success, 2 a gate refused or the command line is wrong, otherwise the plugin's own code — the install layer uses 3 (already exists), 4 (refused to overwrite), 5 (install or self-check failed), 6 (framework mismatch).
This package supports no frameworks; what can be installed is a property of the plugin build it fetches, so the authoritative list is printed every run:
plugin: modelscope/agent-hub-plugin@v0.3.1 (version 0.3.1)
entry : agent_hub_plugin.install() # negotiated: install > fetch_raw > download
scope : frameworks ms-agent, qwenpaw | operations fetch_raw, install, list_backups, restore | planned convert (P2), upload (P1)
Installed user/my-agent
planned names operations the plugin declares but has not implemented; calling one returns ok=False naming the planned release.
Where the plugin may come from is fixed at compile time, not at the command line:
modelscope_hub.constants.AGENT_PLUGIN_TRUSTED_OWNERS, currently modelscope and AI-ModelScope. Checked before anything is downloaded, with no environment override and no per-invocation confirmation: an allow-listed plugin is fetched and run. Widening the list is a reviewed code change.plugin.json's content_sha256 is verified against the files on disk before import. That proves the bytes are the ones the manifest described; it is not authenticity, since the manifest is unsigned and ships beside the code it describes. Origin rests on the allow-list alone.Which build is about to run is logged before the import. The plugin receives your --endpoint and your API token, since it needs credentials to fetch the agent.
Plugins from other owners are not supported. The package format is documented for maintainers in the modelscope_hub.agent._plugin module docstring.
from modelscope_hub.agent import install_agent
outcome = install_agent("owner/my-agent", plugin_revision="v0.3.1")
print(outcome.ok, outcome.operation, outcome.exit_code, outcome.error)
ms-hub agent-idpAgent-IDP manages an Agent's identity and signing key, not its repository files. Use ms-hub agent for raw Agent repository transfer; use ms-hub agent-idp to register an Ed25519 public key, inspect OIDC metadata, and issue a short-lived JWT.
# Private JWK storage is always explicit; the command prints only its public JWK.
ms-hub agent-idp keygen --private-key-out ./agent.jwk
ms-hub agent-idp create --agent-name my-agent --private-key-file ./agent.jwk
ms-hub agent-idp issue-token --agent-id agent_id:modelscope:agent_xxx --audience my-hub --private-key-file ./agent.jwk
# These discovery endpoints are public and do not require login.
ms-hub agent-idp configuration
ms-hub agent-idp jwks
Protect the private JWK file: it is created with mode 0600 on POSIX, never copied into the SDK configuration or cache, and must not be committed. External key stores can pass a public JWK with --public-jwk-file for registration or rotation.
from modelscope_hub import HubApi, generate_agent_key_pair
api = HubApi(token="ms-write-token")
private_jwk, public_jwk = generate_agent_key_pair()
identity = api.create_agent_identity({"agent_name": "my-agent", "public_key": public_jwk.to_dict()})
token = api.issue_agent_token_with_private_key(private_jwk, agent_id=identity.agent_id, audience="my-hub")
All operations go through a single entry point:
from modelscope_hub import HubApi
# Connect to modelscope.cn (default)
api = HubApi(token="...")
# Or connect to modelscope.ai
api = HubApi(token="...", endpoint="https://modelscope.ai")
| Category | Method | Description |
|---|---|---|
| Auth | login(token) | Persist and verify token |
logout() | Clear stored credentials | |
whoami() | Get current user info | |
| Repo | create_repo(repo_id, repo_type, ...) | Create a repository |
get_repo(repo_id, repo_type) | Get repository metadata | |
list_repos(repo_type, ...) | Paginated listing (model, dataset, studio, skill, mcp) | |
delete_repo(repo_id, repo_type) | Delete a repository (deprecated — see note below) | |
repo_exists(repo_id, repo_type) | Check existence | |
| Files | upload_file(repo_id, repo_type, local, remote) | Upload a single file |
upload_folder(repo_id, repo_type, folder, ...) | Upload a directory | |
download_file(repo_id, repo_type, file, ...) | Download a single file (with retry, resume, offline mode) | |
download_repo(repo_id, repo_type, ...) | Download full snapshot (parallel, file lock, progress callbacks) | |
list_repo_files(repo_id, repo_type) | List files in a repo | |
delete_files(repo_id, repo_type, paths) | Remove files (cookie-auth only) | |
| Version | list_repo_revisions(repo_id, repo_type) | List branches and tags |
create_repo_tag(repo_id, repo_type, tag) | Create a tag | |
| Deploy | deploy_repo(repo_id, repo_type) | Deploy Studio or MCP |
stop_repo(repo_id, repo_type) | Stop deployment | |
get_repo_logs(repo_id, ...) | Fetch logs | |
update_repo_settings(repo_id, repo_type, ...) | Update settings | |
| Secrets | add_secret(repo_id, key, value) | Add a secret |
list_secrets(repo_id) | List secret keys (values are never returned) | |
update_secret(repo_id, key, value) | Update a secret | |
delete_secret(repo_id, key) | Delete a secret | |
| Variables | add_variable(repo_id, key, value) | Add a plaintext variable (value is public) |
list_variables(repo_id) | List variables with their values | |
update_variable(repo_id, key, value) | Update a variable | |
delete_variable(repo_id, key) | Delete a variable | |
| Studio resources | list_studio_hardware(...) | Hardware tiers a Studio can run on |
list_studio_base_images() | Available base images | |
list_studio_sdk_versions(...) | Available SDK versions | |
| MCP | list_mcp_servers(...) | List available MCP servers |
list_operational_mcp_servers() | List your hosted servers, with live URLs | |
get_mcp_server(server_id) | Get server details | |
deploy_mcp_server(server_id) | Deploy an MCP server | |
undeploy_mcp_server(server_id) | Undeploy an MCP server | |
| Agent-IDP | create_agent_identity(payload) | Register an Agent Ed25519 public key |
get_agent_identity(agent_id) / update_agent_identity(...) / delete_agent_identity(agent_id) | Manage identity metadata | |
reset_agent_key_pair(agent_id, payload) / pause_agent(agent_id, paused=...) | Rotate a key or control token issuance | |
list_user_agent_identities(...) / list_agent_token_records(...) | List identities and non-sensitive issuance records | |
issue_agent_token_with_private_key(...) | Locally sign and exchange a short-lived JWT | |
get_agent_id_configuration() / get_agent_id_jwks() | Anonymous OIDC discovery and JWT verification keys | |
| Cache | scan_cache(cache_dir) | Inspect local cache |
clear_cache(cache_dir, ...) | Free disk space |
Deletion restrictions:
delete_repois deprecated for security reasons (emitsDeprecationWarning). Will be restored with token-scoped auth. Use the web console instead.delete_filesrequires cookie-based session auth; API tokens (ms-...) may receive a 401 error.
Token permission levels: every write method needs a token issued with
writepermission or higher. A rejected write raisesPermissionDeniedErrorwhosesuggestionnames the required level; an exhausted quota raisesQuotaExceededErrorinstead. See Token permission levels.
modelscope-hub is the hub connectivity layer for the ModelScope ecosystem:
┌────────────────────────────────────────────────┐
│ ModelScope Platform │
│ modelscope.cn · modelscope.ai │
│ │
│ Models · Datasets · Studios · Skills · MCP │
└───────────────────┬────────────────────────────┘
│ OpenAPI / Legacy API
▼
┌───────────────┐
│ modelscope-hub│ ← this library
│ SDK + CLI │
└───┬───────┬───┘
│ │
┌───────┘ └────────┐
▼ ▼
modelscope framework your application
(training · eval) (inference · deploy)
list_repos / ms-hub repo listlocal_files_only--yes flags for non-interactive operationRun ms-hub list --envs to see all configurable environment variables with their current values.
Token is persisted locally after ms-hub login and auto-loaded in subsequent sessions.
Core:
| Variable | Default | Description |
|---|---|---|
MODELSCOPE_API_TOKEN | — | API authentication token |
MODELSCOPE_ENDPOINT | https://modelscope.cn | API endpoint URL |
MODELSCOPE_CACHE | ~/.cache/modelscope | Local cache directory |
MODELSCOPE_HOME | ~/.modelscope | SDK config directory |
MODELSCOPE_PREFER_AI_SITE | false | Prefer modelscope.ai over modelscope.cn |
Network:
| Variable | Default | Description |
|---|---|---|
MODELSCOPE_API_TIMEOUT | 60 | HTTP request timeout (seconds) |
MODELSCOPE_API_CONNECT_TIMEOUT | 10 | HTTP connect timeout (seconds) |
MODELSCOPE_API_MAX_RETRIES | 5 | Max retry attempts for transient failures |
Download:
| Variable | Default | Description |
|---|---|---|
MODELSCOPE_DOWNLOAD_PARALLEL_WORKERS | 1 | Parallel range-download streams |
MODELSCOPE_DOWNLOAD_PARALLEL_THRESHOLD_MB | 500 | Parallel download threshold (MB) |
MODELSCOPE_DOWNLOAD_CHUNK_SIZE_MB | 1 | Streaming chunk size (MB) |
MODELSCOPE_DOWNLOAD_PART_SIZE_MB | 160 | Parallel range chunk size (MB) |
MODELSCOPE_DOWNLOAD_MAX_RETRIES | 5 | Per-file download retry count |
MODELSCOPE_DOWNLOAD_TIMEOUT | 60 | Per-file download timeout (seconds) |
MODELSCOPE_DOWNLOAD_FILE_LOCK | true | File lock for multiprocess download safety |
MODELSCOPE_DOWNLOAD_INTRA_CLOUD | true | Alibaba cloud intra-cloud acceleration |
MODELSCOPE_DOWNLOAD_INTRA_CLOUD_REGION | (auto) | Override intra-cloud region ID |
MODELSCOPE_DOWNLOAD_INTER_CLOUD_REGIONS | Comma-separated peer regions for cross-region internal acceleration (e.g. cn-hangzhou,cn-zhangjiakou) |
Upload:
| Variable | Default | Description |
|---|---|---|
MODELSCOPE_UPLOAD_MAX_CONCURRENT_WORKERS | min(8, cpu+4) | Default parallel worker threads |
MODELSCOPE_UPLOAD_CACHE_ENABLED | true | Enable resumable upload cache; only committed files are skipped on a later run |
MODELSCOPE_UPLOAD_IGNORE_FILE_PATTERN | — | File pattern excluded by legacy push_to_hub uploads |
MODELSCOPE_UPLOAD_MAX_FILE_SIZE_MB | 102400 | Advisory single-file warning threshold (MB); uploads continue above it |
MODELSCOPE_UPLOAD_MAX_FILE_COUNT | 100000 | Advisory total file-count warning threshold; uploads continue above it |
MODELSCOPE_UPLOAD_MAX_FILES_PER_DIRECTORY | 50000 | Advisory per-directory file-count warning threshold |
MODELSCOPE_UPLOAD_NORMAL_FILES_TOTAL_SIZE_MB | 500 | Advisory total inline-file size warning threshold (MB) |
MODELSCOPE_UPLOAD_LFS_FORCE_THRESHOLD | 1MiB | Route larger non-metadata files through LFS; accepts byte-unit suffixes |
MODELSCOPE_UPLOAD_COMMIT_BATCH_MAX_OPERATIONS | 256 | Target actions per commit, clamped to the server hard ceiling |
MODELSCOPE_UPLOAD_COMMIT_MAX_INLINE_BYTES | 8MiB | Estimated commit request-body budget used as the secondary batch constraint |
MODELSCOPE_UPLOAD_COMMIT_MAX_ATTEMPTS | 5 | Maximum attempts for one transient commit failure |
MODELSCOPE_UPLOAD_BLOB_CONNECT_TIMEOUT_SECONDS | 30 | Blob upload connect timeout (seconds) |
MODELSCOPE_UPLOAD_BLOB_READ_TIMEOUT_SECONDS | 3600 | Blob upload read timeout (seconds) |
Capacity thresholds are advisory and emit warnings without blocking upload. Structural errors (invalid paths, missing inputs, changed files) still fail immediately, while the server's per-commit action ceiling is always enforced by splitting. A manual rerun retries every file not marked committed, including files whose previous run ended with a non-retryable error.
Logging:
| Variable | Default | Description |
|---|---|---|
MODELSCOPE_LOG_LEVEL | INFO | SDK log level (DEBUG/INFO/WARNING/ERROR) |
MODELSCOPE_NO_DEPRECATION_WARNINGS | — | Suppress deprecation warnings |
Old variable names (e.g.
API_TIMEOUT,DOWNLOAD_RETRY_TIMES,UPLOAD_USE_CACHE) are deprecated and remain temporarily supported. They emit aFutureWarningand will be removed in a future version. Runms-hub list --envsto see which deprecated names are active in your environment.
modelscope-hub provides a compatibility layer for code written against the old modelscope.hub API surface. The old SDK can delegate directly to modelscope_hub.compat:
from modelscope_hub.compat import snapshot_download, model_file_download
from modelscope_hub.compat import LegacyHubApi as HubApi
All legacy parameter names (allow_file_pattern, ignore_file_pattern, cookies, etc.) are accepted and mapped to the new implementation.
git clone https://github.com/modelscope/modelscope_hub.git
cd modelscope_hub
make install # pip install -e ".[dev]"
make test # unit tests (no network)
make lint # ruff check
make typecheck # mypy
See make help for all available targets.
Apache 2.0 — see LICENSE.
@Misc{modelscope-hub,
title = {modelscope-hub: The official Python client to connect with ModelScope Hub.},
author = {The ModelScope Team},
howpublished = {\url{https://github.com/modelscope/modelscope_hub}},
year = {2026}
}
Python
99.9%
The official Python client to connect with ModelScope Hub.
Python
14
232 commits
updated Sep 21, 2026
The official Python SDK & CLI for ModelScope Hub — download, upload, and manage AI assets from one unified interface.
modelscope-hub connects your code to the ModelScope ecosystem — models, datasets, Studio spaces, skills, and MCP servers — through a single HubApi class or the ms-hub CLI.
modelscope training framework, Studio deployment platform, and MCP server infrastructurev0.4.0 (2026-09-01)
HubApi, ms-hub agent-idp); Studio lists, variables and configuration options; hosted MCP discovery; protected visibility and runtime metadata; read-only tokens can log in and rejected writes name the required tier. Agent private JWKs are only written to an explicitly requested owner-only file.v0.3.1 (2026-09-01)
whoami and legacy responses normalise pre-production field namesv0.3.0 (2026-08-19)
modelscope, ms, modelscope-hub, ms-hub), adds HubApi.get_current_username(), and supports both agent visibility wire formatsrepo/files listings are re-enumerated when the server silently truncates resultsv0.2.0 (2026-08-01)
HubApi.login() now raises NetworkError / ServerError / RequestTimeoutError for non-authentication failures instead of always raising AuthenticationError — widen except AuthenticationError to HubError if you catch any login failure--endpoint modelscope.ai)--endpoint when the token is valid there; --verbose prints the full error cause chainv0.1.9 (2026-07-31)
mcp deploy call-shape assertion and the parse_timestamp timezone-normalization contractms-hub mcp deploy prints the operational URL after deployment; new --auth-check and repeatable --env KEY=VALUE options; --transport-type now validates against sse/streamable_httpcitest workflow — mock-mode test suite (no credentials/network, mirrors distro build sandboxes) on Python 3.10/3.12/3.14 plus ruff/mypy hard gates; releases now require a green test gate before publishing; added a pre-commit configv0.1.8 (2026-07-21)
ms-hub agent raw file transfer (download/upload/list) for remote agent repos; visibility support for agent hub; cache checksum verification (ms-hub cache verify)progress_callbacks through HubApi.download_repo so custom download-progress callbacks work end-to-end; harden legacy (pre-1.38) cache auto-detection (reuse existing {cache}/models/... and default {cache}/hub/models/... layouts); normal (non-LFS) file uploadmodelscope-hub / ms-hub to avoid a file conflict with the modelscope package (e.g. FreeBSD pkg)v0.1.7 (2026-07-07)
snapshot_download cache path with the CLI; add legacy cache fallback--inter-regions CLI arg); cache the region probev0.1.6 (2026-07-03)
v0.1.5 (2026-06-30)
v0.1.4 (2026-06-26)
gated_mode parameter for create_repo; ms-hub create --gated/--no-gated flagscreate_repo extra-kwargs whitelist + type validation; correct visibility mapping (private bool is authoritative)v0.1.3 (2026-06-23)
AlreadyExistsError (E3026) and fix the exist_ok mechanism; align list_repos/RepoInfo with the OpenAPI response formatclear-cache supports all cache layouts (standard/flat/legacy); add last_modified mapping and to_dict() for RepoInfo/PagedResultv0.1.2 (2026-06-23)
list_datasets/get_dataset return format and align parametersv0.1.1 (2026-06-22)
v0.1.0 (2026-06-18)
{cache_dir}/{owner}/{name}/ layoutstr and Path config values)v0.0.9 (2026-06-12)
get_model support revision; expanded param passthrough for repo/model opsparse_timestamp robust timezone conversion for ISO 8601, floats, millisecondsv0.0.8 (2026-06-10)
ms-hub list --all auto-pagination; ms-hub create --skill-file zip upload; ms-hub list --envs--disable-tqdm for folder uploadMODELSCOPE_DOMAIN → MODELSCOPE_ENDPOINTv0.0.5 (2026-06-05)
list_repos pagination and dataset visibility issuesv0.0.4 (2026-06-05)
ms-hub create/info/list/delete)~/.modelscope/credentials/pip install modelscope-hub
Requires Python 3.10+. Lightweight — only requests, tqdm, filelock, urllib3.
This package installs every ModelScope console script, and all four are the same program — pick whichever reads best in your shell:
| Command | Use it for |
|---|---|
modelscope | the primary, brand-level command |
ms | short form of modelscope |
modelscope-hub | explicit hub-only invocation |
ms-hub | short form of modelscope-hub |
Owning all four in one distribution is deliberate: when the umbrella
modelscope SDK also declared
modelscope / ms, installing or upgrading either package could overwrite or
delete the other's scripts and leave you with no CLI at all. OS packagers (such
as FreeBSD pkg) likewise refuse to let two ports own the same path. The SDK now
contributes its extra commands as plugins instead.
So modelscope and ms work on a hub-only install too. Commands that belong to
the full SDK (pipeline, server, studio, modelcard, …) appear once you
also pip install modelscope; until then --help says so. The two *-hub
aliases always report just this package, which is handy for scripts that must
pin the lightweight client:
ms-hub --version # modelscope-hub X.Y.Z
modelscope --version # modelscope A.B.C (modelscope-hub X.Y.Z)
ms-hub login
# or pass a token directly
ms-hub login --token $MODELSCOPE_API_TOKEN
Get your token at modelscope.cn/my/access/token or modelscope.ai/my/access/token.
from modelscope_hub import HubApi
api = HubApi(token="your-token")
user = api.whoami()
print(user.username)
# Full snapshot
ms-hub download Qwen/Qwen3-0.6B
# Single file
ms-hub download Qwen/Qwen3-0.6B config.json
# With filters
ms-hub download Qwen/Qwen3-0.6B --include "*.safetensors" --exclude "*.bin"
# Directly into a local directory (bypasses cache)
ms-hub download Qwen/Qwen3-0.6B --local-dir ./my-model
path = api.download_file("Qwen/Qwen3-0.6B", "model", "config.json")
snapshot = api.download_repo(
"Qwen/Qwen3-0.6B", "model",
allow_patterns=["*.safetensors", "*.json"],
max_workers=8,
)
# Offline mode — return cached path without network access
path = api.download_file("Qwen/Qwen3-0.6B", "model", "config.json", local_files_only=True)
ms-hub upload my-org/my-model ./weights.safetensors
ms-hub upload my-org/my-model ./output --repo-type model --commit-message "add weights"
api.upload_file("my-org/my-model", "model", "./weights.safetensors", "weights.safetensors")
api.upload_folder("my-org/my-model", "model", "./output", path_in_repo="")
ms-hub create my-org/my-model --repo-type model --visibility private
api.create_repo("my-org/my-model", "model", visibility="private", license="apache-2.0")
ms-hub deploy my-org/chat-demo --repo-type studio
ms-hub logs my-org/chat-demo --log-type run
ms-hub stop my-org/chat-demo --repo-type studio
api.deploy_repo("my-org/chat-demo", "studio")
api.get_repo_logs("my-org/chat-demo", log_type="run")
api.stop_repo("my-org/chat-demo", "studio")
The CLI is available as both ms-hub and modelscope-hub.
Global options (placed before or after the subcommand):
| Option | Description |
|---|---|
--token TOKEN | API token (overrides env and persisted token) |
--endpoint URL | API endpoint (default: https://modelscope.cn) |
-v, --verbose | Enable DEBUG logging (global only) |
-V, --version | Print version and exit (global only) |
--tokenand--endpointcan be placed either before or after the subcommand:ms-hub --token xxx download ...andms-hub download ... --token xxxare equivalent.
ms-hub loginAuthenticate and persist your token locally.
ms-hub login # interactive prompt
ms-hub login --token $MY_TOKEN # non-interactive
| Option | Description |
|---|---|
--token TOKEN | API token; prompted interactively if omitted |
Tokens are issued with one of three permission levels, set when you create the token at modelscope.cn/my/myaccesstoken:
| Level | Can do |
|---|---|
read | Browse and download; list your Studios, secrets and variables |
write | Everything above, plus create/upload/deploy and change settings |
admin | Everything above, plus administrative operations |
What this means in practice:
ms-hub login succeeds and prints a warning
that git and session credentials were not issued, so pushes and uploads will
need a write token. Downloads and browsing work normally.[E3002] Permission denied and a suggestion naming the level the
operation requires, rather than leaving you to guess.PermissionDeniedError and
QuotaExceededError (the latter is never retried, since retrying an exhausted
quota only delays the error).The SDK cannot tell you which level your token has: the API does not report it. Check the token settings page if you are unsure.
ms-hub whoamiShow the user associated with the current token.
ms-hub whoami
ms-hub whoami --token $MY_TOKEN # check a specific token without logging in
ms-hub downloadDownload a single file or a full repository snapshot.
ms-hub download Qwen/Qwen3-0.6B # full snapshot
ms-hub download Qwen/Qwen3-0.6B config.json # single file
ms-hub download Qwen/Qwen3-0.6B --include "*.safetensors" # filter by glob
ms-hub download Qwen/Qwen3-0.6B --local-dir ./out --max-workers 8 # direct download
ms-hub download my-org/my-data --repo-type dataset --revision v2 # dataset at tag
| Argument / Option | Required | Description |
|---|---|---|
repo_id | yes | Repository identifier (owner/name) |
files... | no | Specific file paths; omit for full snapshot |
--repo-type {model,dataset} | no | Default: model |
--revision REV | no | Branch, tag, or commit hash (default: master) |
--local-dir DIR | no | Download directly here (bypasses cache layout) |
--cache-dir DIR | no | Override default cache directory |
--include GLOB... | no | Only download matching files; repeatable |
--exclude GLOB... | no | Skip matching files; repeatable |
--max-workers N | no | Parallel download threads (default: 4) |
--force | no | Re-download even if cached |
# Download multiple specific files at once
ms-hub download Qwen/Qwen3-0.6B config.json tokenizer.json generation_config.json
# Download only safetensors, skip GGUF and bin weights
ms-hub download Qwen/Qwen3-0.6B --include "*.safetensors" --exclude "*.bin" "*.gguf"
# Download a dataset at a specific tag into a local directory
ms-hub download my-org/my-data --repo-type dataset --revision v2 --local-dir ./data
# Use a custom cache directory and 8 parallel threads
ms-hub download Qwen/Qwen3-0.6B --cache-dir /data/hub-cache --max-workers 8
# Force re-download even if already cached
ms-hub download Qwen/Qwen3-0.6B config.json --force
# Download all skills from a collection (legacy flag)
ms-hub download --collection my-org/skill-collection
# Enable parallel range download for large files (env var)
MODELSCOPE_DOWNLOAD_PARALLELS=4 ms-hub download Qwen/Qwen3-0.6B
# Use the modelscope.ai endpoint (global option, before subcommand)
ms-hub --endpoint https://modelscope.ai download Qwen/Qwen3-0.6B
ms-hub uploadUpload a file or folder to a repository.
ms-hub upload my-org/my-model ./weights.safetensors # single file
ms-hub upload my-org/my-model ./output models/ --repo-type model # folder → subdir
ms-hub upload my-org/my-model . --include "*.py" --commit-message "code" # filtered folder
| Argument / Option | Required | Description |
|---|---|---|
repo_id | yes | Repository identifier |
local_path | no | Local file or folder (default: inferred from repo name) |
path_in_repo | no | Destination path inside the repo |
--repo-type {model,dataset} | no | Default: model |
--revision REV | no | Target branch (default: master) |
--commit-message MSG | no | Commit message |
--commit-description DESC | no | Extended commit description |
--include GLOB... | no | Include filter for folder mode; repeatable |
--exclude GLOB... | no | Exclude filter for folder mode; repeatable |
--max-workers N | no | Parallel upload threads |
--use-cache / --no-cache | no | Enable/disable resumable upload cache (default: on) |
--disable-tqdm | no | Disable progress bars |
# Upload a single file with a custom commit message
ms-hub upload my-org/my-model ./weights.safetensors --commit-message "add fp16 weights"
# Upload a folder into a subdirectory of the repo
ms-hub upload my-org/my-model ./output models/ --repo-type model
# Upload only Python files from the current directory
ms-hub upload my-org/my-model . --include "*.py" --commit-message "update code"
# Upload only safetensors, skip checkpoints
ms-hub upload my-org/my-model ./output --include "*.safetensors" --exclude "*.ckpt" "*.bin"
# Upload to a dataset repo on a specific branch
ms-hub upload my-org/my-data ./data --repo-type dataset --revision dev
# Upload with extended commit description
ms-hub upload my-org/my-model ./weights.safetensors \
--commit-message "v2 weights" \
--commit-description "Retrained with extended dataset, 3 epochs, lr=2e-5"
# Resumable upload: interrupted uploads resume automatically via cache
ms-hub upload my-org/my-model ./large-folder
# If interrupted, just re-run the same command — already uploaded files are skipped
# Disable upload cache (no resume, fresh upload every time)
ms-hub upload my-org/my-model ./output --no-cache
# Disable progress bars (useful for CI/CD pipelines)
ms-hub upload my-org/my-model ./output --disable-tqdm
ms-hub create / ms-hub info / ms-hub list / ms-hub deleteRepository management.
ms-hub create my-org/my-model --repo-type model --visibility private
ms-hub create my-org/demo --repo-type studio --sdk-type gradio
ms-hub info my-org/my-model --repo-type model
ms-hub list --repo-type model --owner my-org --page-size 20
ms-hub list --repo-type studio --owner my-org
ms-hub delete my-org/my-model --repo-type model --yes
Deprecation notice:
delete_repo/ms-hub deleteemits aDeprecationWarning— programmatic repo deletion is restricted for security reasons and will be restored once token-scoped auth is available. Use the web console to delete repos.
delete_filesrequires cookie-based session auth; API tokens may receive a 401 error.
ms-hub create options| Argument / Option | Required | Description |
|---|---|---|
repo_id | yes | Repository identifier |
--repo-type | yes | model, dataset, studio, or skill |
--visibility | no | public, private or internal. For Studios also protected (app public, code repository hidden) |
--license | no | SPDX license identifier (e.g. apache-2.0) |
--chinese-name | no | Display name in Chinese |
--description | no | Repository description |
--exist-ok | no | No error if repository already exists |
--sdk-type | no | Studio SDK: gradio, streamlit, docker, static |
--sdk-version | no | Studio SDK version |
--base-image | no | Studio base Docker image |
--cover-image | no | Studio cover image URL |
--hardware | no | Studio hardware spec |
ms-hub deploy / ms-hub stop / ms-hub logs / ms-hub settingsManage Studio and MCP deployments.
ms-hub deploy my-org/chat-demo --repo-type studio
ms-hub logs my-org/chat-demo --log-type run --keyword ERROR --page-size 50
ms-hub settings my-org/chat-demo cpu=4 memory=8192
ms-hub stop my-org/chat-demo --repo-type studio
| Command | --repo-type | Key Options |
|---|---|---|
ms-hub deploy <repo_id> | {studio,mcp} (default: studio) | — |
ms-hub stop <repo_id> | {studio,mcp} (default: studio) | — |
ms-hub logs <repo_id> | {studio} only | --log-type {run,build}, --keyword, --page, --page-size |
ms-hub settings <repo_id> key=val... | {studio,skill} (default: studio) | Key-value pairs passed to backend |
Note:
ms-hub logsonly supports Studio spaces. MCP server logs are not available via this command.ms-hub settingssupports Studio and Skill repos; for MCP servers usems-hub mcp deploywith configuration payload.
ms-hub secret / ms-hub studio variableManage a Studio's environment variables. Two commands, because the disclosure differs: a secret's value is never returned by the API, a variable's value is publicly visible.
# Secrets — values are write-only
ms-hub secret add my-org/demo API_KEY sk-xxx
ms-hub secret list my-org/demo
ms-hub secret update my-org/demo API_KEY sk-new
ms-hub secret delete my-org/demo API_KEY --yes
# Plaintext variables — values are readable by anyone
ms-hub studio variable add my-org/demo MODEL_NAME Qwen2.5-7B
ms-hub studio variable list my-org/demo
ms-hub studio variable update my-org/demo MODEL_NAME Qwen2.5-14B
ms-hub studio variable delete my-org/demo MODEL_NAME --yes
| Subcommand | Arguments | Description |
|---|---|---|
add | repo_id key value | Add a new entry |
list | repo_id | List entries (secret shows keys only; variable shows keys and values) |
update | repo_id key value | Update a value |
delete | repo_id key [--yes] | Delete an entry |
ms-hub secret accepts --repo-type (default: studio, currently the only supported type).
Put anything sensitive in a secret. A plaintext variable's value is public.
ms-hub studioBrowse Studio spaces and the runtime resources they can be configured with.
# Browse
ms-hub studio list --search chat --sort likes --page-size 20
ms-hub studio list --owner my-org --status all
ms-hub studio list --mcp-support --hardware-type xgpu
# Discover valid values for --hardware / --base-image / --sdk-version
ms-hub studio hardware --sdk-type gradio
ms-hub studio hardware --studio my-org/demo
ms-hub studio base-images
ms-hub studio sdk-versions --sdk-type gradio
# Runtime management (also available as the top-level deploy/stop/logs/settings)
ms-hub studio deploy my-org/demo
ms-hub studio logs my-org/demo --type build
ms-hub studio settings my-org/demo --visibility protected
| Subcommand | Arguments | Key Options |
|---|---|---|
list | — | --search, --owner, --sort {default,last_modified,view_num,likes}, --status {running,all}, --mcp-support/--no-mcp-support, --hardware-type {xgpu,amd}, --page, --page-size |
hardware | — | --sdk-type, --studio owner/name |
base-images | — | — |
sdk-versions | — | --sdk-type (default gradio; only gradio publishes versions) |
deploy / stop | studio_id | — |
logs | studio_id | --type {run,build}, --keyword, --page, --page-size (max 500) |
settings | studio_id [key=val...] | --display-name, --description, --license, --cover-image, --sdk-type, --sdk-version, --base-image, --hardware, --visibility, --private/--public |
secret | see above | — |
variable | see above | — |
--visibility accepts three values: public (code and app public), protected
(app public, code repository hidden) and private. --private / --public
remain as shorthands.
Paid hardware tiers are selected as --hardware paid/<instance_type>; run
ms-hub studio hardware to see the available identifiers.
--status defaults to all whenever --owner is given, so listing your own
spaces includes stopped ones. Without --owner the server's own default applies
(running spaces only).
ms-hub mcpManage MCP (Model Context Protocol) servers.
ms-hub mcp list --search weather --page-size 10
ms-hub mcp list --hosted # only your own hosted servers, with live URLs
ms-hub mcp info my-org/weather-mcp
ms-hub mcp deploy my-org/weather-mcp
ms-hub mcp undeploy my-org/weather-mcp
| Subcommand | Arguments | Key Options |
|---|---|---|
list | — | --search, --hosted, --page, --page-size |
info | server_id | — |
deploy | server_id | --transport-type, --expiration-minutes, --auth-check, --env KEY=VALUE |
undeploy | server_id | — |
--hosted lists the servers you currently have hosted along with their
operational_urls. It takes no search or paging options, because the underlying
endpoint accepts none.
Discovery is capped at
page * page_size <= 100by the service.
ms-hub cacheInspect and clean the local download cache.
ms-hub cache scan
ms-hub cache scan --cache-dir /data/cache
ms-hub cache verify Qwen/Qwen3-0.6B
ms-hub cache verify Qwen/Qwen3-0.6B --local-dir ./Qwen3-0.6B
ms-hub cache clear --repo-type model --yes
ms-hub cache clear --repo-id my-org/old-model --repo-type model --yes
| Subcommand | Key Options |
|---|---|
scan | --cache-dir DIR |
verify REPO_ID | --repo-type, --revision, --cache-dir, --local-dir, --fail-on-missing-files, --fail-on-extra-files |
clear | --repo-type, --repo-id, --cache-dir, --yes |
ms-hub agentRemote agent repositories: raw file transfer (download, upload, list) and plugin-driven install.
ms-hub agent download -r user/my-agent --local-dir ./my-agent # download raw files
ms-hub agent upload -r user/my-agent --local-dir ./my-agent # upload raw
ms-hub agent install -r user/my-agent # install into the framework
download / upload / list transfer files as-is, with no framework awareness.
install is different: it fetches an official plugin and hands the agent id to it, leaving every framework decision to the plugin. See ms-hub agent install for the details and the security model.
Framework-aware operations (cross-framework
convert,watch/bidirectional sync,status,backups,restore,stop) live in modelscope-agent — usems-agent agent ...instead. For example, to download and convert in one step:ms-agent agent download -f qoder -r user/my-agent --target-framework qwenpaw.
ms-hub agent downloadDownload all files of a remote agent repository to a local directory (raw, no conversion).
ms-hub agent download -r user/my-agent
ms-hub agent download -r user/my-agent --local-dir ./my-agent --revision master
| Option | Required | Description |
|---|---|---|
-r, --repo REPO | yes | Remote repo identifier (owner/name) |
--local-dir DIR | no | Destination directory (default: ./<repo-name> under CWD) |
--revision REV | no | Repository revision (default: master) |
ms-hub agent uploadUpload files from a local path (file or directory) to a remote agent repository (raw, no conversion). Creates the repo if it does not exist.
ms-hub agent upload -r user/my-agent --local-dir ./my-agent
ms-hub agent upload -r user/my-agent --local-dir ./my-agent --dry-run
| Option | Required | Description |
|---|---|---|
-r, --repo REPO | yes | Remote repo identifier (owner/name) |
--local-dir DIR | no | Source path (file or directory) to upload (default: CWD) |
--revision REV | no | Repository revision (default: master) |
--dry-run | no | List files that would be uploaded without uploading |
ms-hub agent installDownload an agent and hand it to its framework plugin. A plugin with an install entry point places the agent into the framework's workspace; one that only transports bytes writes the repository's files into a destination directory and leaves placement to whatever runs next. The command reports which happened (Installed … vs Fetched …).
ms-hub agent install -r user/my-agent
| Option | Required | Description |
|---|---|---|
-r, --repo REPO | yes | Agent repository to install (owner/name) |
--plugin-revision REV | no | Plugin revision (default: master; pin a tag for reproducible installs) |
-n, --name NAME | no | Sub-agent name, passed through to the plugin |
--framework FW | no | Override the plugin's framework detection |
--local-dir DIR | no | Where the agent repository is downloaded, not where it is installed. Omitted, downloads go to $MODELSCOPE_CACHE/agent/agent-staging/<owner>--<name>-<timestamp>/ and are cleaned up on success |
--dry-run | no | Ask the plugin to report instead of change anything. The plugin is still downloaded, imported and run — only its writes are suppressed |
-y, --yes / --force / -q, --quiet | no | Passed through to the plugin |
Exit codes: 0 success, 2 a gate refused or the command line is wrong, otherwise the plugin's own code — the install layer uses 3 (already exists), 4 (refused to overwrite), 5 (install or self-check failed), 6 (framework mismatch).
This package supports no frameworks; what can be installed is a property of the plugin build it fetches, so the authoritative list is printed every run:
plugin: modelscope/agent-hub-plugin@v0.3.1 (version 0.3.1)
entry : agent_hub_plugin.install() # negotiated: install > fetch_raw > download
scope : frameworks ms-agent, qwenpaw | operations fetch_raw, install, list_backups, restore | planned convert (P2), upload (P1)
Installed user/my-agent
planned names operations the plugin declares but has not implemented; calling one returns ok=False naming the planned release.
Where the plugin may come from is fixed at compile time, not at the command line:
modelscope_hub.constants.AGENT_PLUGIN_TRUSTED_OWNERS, currently modelscope and AI-ModelScope. Checked before anything is downloaded, with no environment override and no per-invocation confirmation: an allow-listed plugin is fetched and run. Widening the list is a reviewed code change.plugin.json's content_sha256 is verified against the files on disk before import. That proves the bytes are the ones the manifest described; it is not authenticity, since the manifest is unsigned and ships beside the code it describes. Origin rests on the allow-list alone.Which build is about to run is logged before the import. The plugin receives your --endpoint and your API token, since it needs credentials to fetch the agent.
Plugins from other owners are not supported. The package format is documented for maintainers in the modelscope_hub.agent._plugin module docstring.
from modelscope_hub.agent import install_agent
outcome = install_agent("owner/my-agent", plugin_revision="v0.3.1")
print(outcome.ok, outcome.operation, outcome.exit_code, outcome.error)
ms-hub agent-idpAgent-IDP manages an Agent's identity and signing key, not its repository files. Use ms-hub agent for raw Agent repository transfer; use ms-hub agent-idp to register an Ed25519 public key, inspect OIDC metadata, and issue a short-lived JWT.
# Private JWK storage is always explicit; the command prints only its public JWK.
ms-hub agent-idp keygen --private-key-out ./agent.jwk
ms-hub agent-idp create --agent-name my-agent --private-key-file ./agent.jwk
ms-hub agent-idp issue-token --agent-id agent_id:modelscope:agent_xxx --audience my-hub --private-key-file ./agent.jwk
# These discovery endpoints are public and do not require login.
ms-hub agent-idp configuration
ms-hub agent-idp jwks
Protect the private JWK file: it is created with mode 0600 on POSIX, never copied into the SDK configuration or cache, and must not be committed. External key stores can pass a public JWK with --public-jwk-file for registration or rotation.
from modelscope_hub import HubApi, generate_agent_key_pair
api = HubApi(token="ms-write-token")
private_jwk, public_jwk = generate_agent_key_pair()
identity = api.create_agent_identity({"agent_name": "my-agent", "public_key": public_jwk.to_dict()})
token = api.issue_agent_token_with_private_key(private_jwk, agent_id=identity.agent_id, audience="my-hub")
All operations go through a single entry point:
from modelscope_hub import HubApi
# Connect to modelscope.cn (default)
api = HubApi(token="...")
# Or connect to modelscope.ai
api = HubApi(token="...", endpoint="https://modelscope.ai")
| Category | Method | Description |
|---|---|---|
| Auth | login(token) | Persist and verify token |
logout() | Clear stored credentials | |
whoami() | Get current user info | |
| Repo | create_repo(repo_id, repo_type, ...) | Create a repository |
get_repo(repo_id, repo_type) | Get repository metadata | |
list_repos(repo_type, ...) | Paginated listing (model, dataset, studio, skill, mcp) | |
delete_repo(repo_id, repo_type) | Delete a repository (deprecated — see note below) | |
repo_exists(repo_id, repo_type) | Check existence | |
| Files | upload_file(repo_id, repo_type, local, remote) | Upload a single file |
upload_folder(repo_id, repo_type, folder, ...) | Upload a directory | |
download_file(repo_id, repo_type, file, ...) | Download a single file (with retry, resume, offline mode) | |
download_repo(repo_id, repo_type, ...) | Download full snapshot (parallel, file lock, progress callbacks) | |
list_repo_files(repo_id, repo_type) | List files in a repo | |
delete_files(repo_id, repo_type, paths) | Remove files (cookie-auth only) | |
| Version | list_repo_revisions(repo_id, repo_type) | List branches and tags |
create_repo_tag(repo_id, repo_type, tag) | Create a tag | |
| Deploy | deploy_repo(repo_id, repo_type) | Deploy Studio or MCP |
stop_repo(repo_id, repo_type) | Stop deployment | |
get_repo_logs(repo_id, ...) | Fetch logs | |
update_repo_settings(repo_id, repo_type, ...) | Update settings | |
| Secrets | add_secret(repo_id, key, value) | Add a secret |
list_secrets(repo_id) | List secret keys (values are never returned) | |
update_secret(repo_id, key, value) | Update a secret | |
delete_secret(repo_id, key) | Delete a secret | |
| Variables | add_variable(repo_id, key, value) | Add a plaintext variable (value is public) |
list_variables(repo_id) | List variables with their values | |
update_variable(repo_id, key, value) | Update a variable | |
delete_variable(repo_id, key) | Delete a variable | |
| Studio resources | list_studio_hardware(...) | Hardware tiers a Studio can run on |
list_studio_base_images() | Available base images | |
list_studio_sdk_versions(...) | Available SDK versions | |
| MCP | list_mcp_servers(...) | List available MCP servers |
list_operational_mcp_servers() | List your hosted servers, with live URLs | |
get_mcp_server(server_id) | Get server details | |
deploy_mcp_server(server_id) | Deploy an MCP server | |
undeploy_mcp_server(server_id) | Undeploy an MCP server | |
| Agent-IDP | create_agent_identity(payload) | Register an Agent Ed25519 public key |
get_agent_identity(agent_id) / update_agent_identity(...) / delete_agent_identity(agent_id) | Manage identity metadata | |
reset_agent_key_pair(agent_id, payload) / pause_agent(agent_id, paused=...) | Rotate a key or control token issuance | |
list_user_agent_identities(...) / list_agent_token_records(...) | List identities and non-sensitive issuance records | |
issue_agent_token_with_private_key(...) | Locally sign and exchange a short-lived JWT | |
get_agent_id_configuration() / get_agent_id_jwks() | Anonymous OIDC discovery and JWT verification keys | |
| Cache | scan_cache(cache_dir) | Inspect local cache |
clear_cache(cache_dir, ...) | Free disk space |
Deletion restrictions:
delete_repois deprecated for security reasons (emitsDeprecationWarning). Will be restored with token-scoped auth. Use the web console instead.delete_filesrequires cookie-based session auth; API tokens (ms-...) may receive a 401 error.
Token permission levels: every write method needs a token issued with
writepermission or higher. A rejected write raisesPermissionDeniedErrorwhosesuggestionnames the required level; an exhausted quota raisesQuotaExceededErrorinstead. See Token permission levels.
modelscope-hub is the hub connectivity layer for the ModelScope ecosystem:
┌────────────────────────────────────────────────┐
│ ModelScope Platform │
│ modelscope.cn · modelscope.ai │
│ │
│ Models · Datasets · Studios · Skills · MCP │
└───────────────────┬────────────────────────────┘
│ OpenAPI / Legacy API
▼
┌───────────────┐
│ modelscope-hub│ ← this library
│ SDK + CLI │
└───┬───────┬───┘
│ │
┌───────┘ └────────┐
▼ ▼
modelscope framework your application
(training · eval) (inference · deploy)
list_repos / ms-hub repo listlocal_files_only--yes flags for non-interactive operationRun ms-hub list --envs to see all configurable environment variables with their current values.
Token is persisted locally after ms-hub login and auto-loaded in subsequent sessions.
Core:
| Variable | Default | Description |
|---|---|---|
MODELSCOPE_API_TOKEN | — | API authentication token |
MODELSCOPE_ENDPOINT | https://modelscope.cn | API endpoint URL |
MODELSCOPE_CACHE | ~/.cache/modelscope | Local cache directory |
MODELSCOPE_HOME | ~/.modelscope | SDK config directory |
MODELSCOPE_PREFER_AI_SITE | false | Prefer modelscope.ai over modelscope.cn |
Network:
| Variable | Default | Description |
|---|---|---|
MODELSCOPE_API_TIMEOUT | 60 | HTTP request timeout (seconds) |
MODELSCOPE_API_CONNECT_TIMEOUT | 10 | HTTP connect timeout (seconds) |
MODELSCOPE_API_MAX_RETRIES | 5 | Max retry attempts for transient failures |
Download:
| Variable | Default | Description |
|---|---|---|
MODELSCOPE_DOWNLOAD_PARALLEL_WORKERS | 1 | Parallel range-download streams |
MODELSCOPE_DOWNLOAD_PARALLEL_THRESHOLD_MB | 500 | Parallel download threshold (MB) |
MODELSCOPE_DOWNLOAD_CHUNK_SIZE_MB | 1 | Streaming chunk size (MB) |
MODELSCOPE_DOWNLOAD_PART_SIZE_MB | 160 | Parallel range chunk size (MB) |
MODELSCOPE_DOWNLOAD_MAX_RETRIES | 5 | Per-file download retry count |
MODELSCOPE_DOWNLOAD_TIMEOUT | 60 | Per-file download timeout (seconds) |
MODELSCOPE_DOWNLOAD_FILE_LOCK | true | File lock for multiprocess download safety |
MODELSCOPE_DOWNLOAD_INTRA_CLOUD | true | Alibaba cloud intra-cloud acceleration |
MODELSCOPE_DOWNLOAD_INTRA_CLOUD_REGION | (auto) | Override intra-cloud region ID |
MODELSCOPE_DOWNLOAD_INTER_CLOUD_REGIONS | Comma-separated peer regions for cross-region internal acceleration (e.g. cn-hangzhou,cn-zhangjiakou) |
Upload:
| Variable | Default | Description |
|---|---|---|
MODELSCOPE_UPLOAD_MAX_CONCURRENT_WORKERS | min(8, cpu+4) | Default parallel worker threads |
MODELSCOPE_UPLOAD_CACHE_ENABLED | true | Enable resumable upload cache; only committed files are skipped on a later run |
MODELSCOPE_UPLOAD_IGNORE_FILE_PATTERN | — | File pattern excluded by legacy push_to_hub uploads |
MODELSCOPE_UPLOAD_MAX_FILE_SIZE_MB | 102400 | Advisory single-file warning threshold (MB); uploads continue above it |
MODELSCOPE_UPLOAD_MAX_FILE_COUNT | 100000 | Advisory total file-count warning threshold; uploads continue above it |
MODELSCOPE_UPLOAD_MAX_FILES_PER_DIRECTORY | 50000 | Advisory per-directory file-count warning threshold |
MODELSCOPE_UPLOAD_NORMAL_FILES_TOTAL_SIZE_MB | 500 | Advisory total inline-file size warning threshold (MB) |
MODELSCOPE_UPLOAD_LFS_FORCE_THRESHOLD | 1MiB | Route larger non-metadata files through LFS; accepts byte-unit suffixes |
MODELSCOPE_UPLOAD_COMMIT_BATCH_MAX_OPERATIONS | 256 | Target actions per commit, clamped to the server hard ceiling |
MODELSCOPE_UPLOAD_COMMIT_MAX_INLINE_BYTES | 8MiB | Estimated commit request-body budget used as the secondary batch constraint |
MODELSCOPE_UPLOAD_COMMIT_MAX_ATTEMPTS | 5 | Maximum attempts for one transient commit failure |
MODELSCOPE_UPLOAD_BLOB_CONNECT_TIMEOUT_SECONDS | 30 | Blob upload connect timeout (seconds) |
MODELSCOPE_UPLOAD_BLOB_READ_TIMEOUT_SECONDS | 3600 | Blob upload read timeout (seconds) |
Capacity thresholds are advisory and emit warnings without blocking upload. Structural errors (invalid paths, missing inputs, changed files) still fail immediately, while the server's per-commit action ceiling is always enforced by splitting. A manual rerun retries every file not marked committed, including files whose previous run ended with a non-retryable error.
Logging:
| Variable | Default | Description |
|---|---|---|
MODELSCOPE_LOG_LEVEL | INFO | SDK log level (DEBUG/INFO/WARNING/ERROR) |
MODELSCOPE_NO_DEPRECATION_WARNINGS | — | Suppress deprecation warnings |
Old variable names (e.g.
API_TIMEOUT,DOWNLOAD_RETRY_TIMES,UPLOAD_USE_CACHE) are deprecated and remain temporarily supported. They emit aFutureWarningand will be removed in a future version. Runms-hub list --envsto see which deprecated names are active in your environment.
modelscope-hub provides a compatibility layer for code written against the old modelscope.hub API surface. The old SDK can delegate directly to modelscope_hub.compat:
from modelscope_hub.compat import snapshot_download, model_file_download
from modelscope_hub.compat import LegacyHubApi as HubApi
All legacy parameter names (allow_file_pattern, ignore_file_pattern, cookies, etc.) are accepted and mapped to the new implementation.
git clone https://github.com/modelscope/modelscope_hub.git
cd modelscope_hub
make install # pip install -e ".[dev]"
make test # unit tests (no network)
make lint # ruff check
make typecheck # mypy
See make help for all available targets.
Apache 2.0 — see LICENSE.
@Misc{modelscope-hub,
title = {modelscope-hub: The official Python client to connect with ModelScope Hub.},
author = {The ModelScope Team},
howpublished = {\url{https://github.com/modelscope/modelscope_hub}},
year = {2026}
}
Python
99.9%