Skip to content

Alist API 封装,客户端支持同步和异步,全部的请求和响应都有完整的数据校验。支持pathlib的路径风格,体验使用更接近Python调用原生文件系统。一个简单的命令行工具正在开发中。

Notifications You must be signed in to change notification settings

lee-cq/alist-sdk

Repository files navigation

Alist Sdk

Alist SDK - Test

Alist API 封装,客户端支持同步和异步,全部的请求和响应都有完整的数据校验。支持pathlib的路径风格,体验使用更接近Python调用原生文件系统。 一个简单的命令行工具正在开发中。

安装

alist-sdk 支持 Python 3.10+ 依赖:

  • "httpx>=0.25.1" HTTP客户端库
  • "pydantic>=2.5.1" 数据校验库
  • "typer>=0.12.5" 命令行工具集成

从PyPI安装最新release版本
pip install alist-sdk

从GitHub安装dev版本
pip install git+https://github.com/lee-cq/alist-sdk.git

使用

客户端或异步客户端方法的签名与Alist API基本一致。

# Sync 模式
from alist_sdk import Client

client = Client(
    base_url='http://localhost:5244',
    username="",
    password="",
    token="",  # 与 Username Password 二选一
)

client.me()
client.mkdir("/local/test")
# Async 模式
import asyncio
from alist_sdk import AsyncClient

client = AsyncClient(
    base_url='http://localhost:5244',
    username="",
    password="",
    token="",  # 与 Username Password 二选一
)

asyncio.run(client.me())

像使用pathlib一样操作Alist上的文件。 但是需要注意的是,AlistPath全部使用的同步方法(与Pathlib API保持一致)。 如果需要异步操作,可以使用asyncio.to_thread将同步方法转为异步方法。

from alist_sdk.path_lib import login_server, AlistPath

# 登录方式1
login_server("http://localhost:5244", username='admin', password='123456')
path = AlistPath('http://localhost:5244/test')

# 登录方式2 version > 0.36.13
path = AlistPath('http://localhost:5244/test', username='admin', password='123456')

path.stat()
path.is_dir()
path.read_text()
path.iterdir()

命令行工具 [开发中]

Alist SDK 提供了2个命令行工具,可以方便的操作Alist。

  1. alist-cli:命令行工具,可以快速的操作Alist。
  2. alist-fs:(alist-cli fs 的别名)文件相关操作,包括上传、下载、删除、查看文件信息等。
Usage: alist-cli [OPTIONS] COMMAND [ARGS]...
Options:
│ --install-completion          Install completion for the current shell.                                                                                                                                                            │
│ --show-completion             Show completion for the current shell, to copy it or customize the installation.                                                                                                                     │
│ --help   
    
Commands:
│ admin   管理命令                                                                                                                                                                                                                   │
│ auth    Authentication commands.                                                                                                                                                                                                   │
│ fs      文件系统相关操作  

About

Alist API 封装,客户端支持同步和异步,全部的请求和响应都有完整的数据校验。支持pathlib的路径风格,体验使用更接近Python调用原生文件系统。一个简单的命令行工具正在开发中。

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published