# 百度网盘 Web API 的 Python 封装
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/python-dupan)
![PyPI - Version](https://img.shields.io/pypi/v/python-dupan)
![PyPI - Downloads](https://img.shields.io/pypi/dm/python-dupan)
![PyPI - Format](https://img.shields.io/pypi/format/python-dupan)
![PyPI - Status](https://img.shields.io/pypi/status/python-dupan)
## 安装
通过 [pypi](https://pypi.org/project/python-dupan/)
```console
pip install -U python-dupan
```
## 入门介绍
### 1. 导入模块和创建实例
**导入模块**
```python
from dupan import DuPanClient, DuPanFileSystem
```
**创建客户端对象,需要传入 <kbd>cookie</kbd>,如果不传或者 <kbd>cookie</kbd> 失效,则需要扫码登录**
```python
cookie = "BDUSS=...;STOKEN=..."
client = DuPanClient(cookie)
```
**创建文件系统对象**
```python
fs = DuPanFileSystem(client)
```
或者直接在 <kbd>client</kbd> 上就可获取文件系统对象
```python
fs = client.fs
```
或者直接用 <kbd>DuPanFileSystem</kbd> 登录
```python
fs = DuPanFileSystem.login(cookie)
```
### 2. 操作网盘使用 Python 式的文件系统方法
文件系统对象的方法,设计和行为参考了 <kbd>[os](https://docs.python.org/3/library/os.html)</kbd>、<kbd>[posixpath](https://docs.python.org/3/library/os.path.html)</kbd>、<kbd>[pathlib.Path](https://docs.python.org/3/library/pathlib.html)</kbd> 和 <kbd>[shutil](https://docs.python.org/3/library/shutil.html)</kbd> 等模块。
<kbd>dupan.DuPanFileSystem</kbd> 实现了读写的文件系统方法。
| 方法 | 说明 | 参考|
| --- | --- | --- |
| <kbd>\_\_contains\_\_()</kbd><br /><kbd>path in fs</kbd> | 判断路径是否存在 | <kbd>exists()</kbd> |
| <kbd>\_\_delitem\_\_()</kbd><br /><kbd>del fs[path]</kbd> | 删除文件或目录 | <kbd>rmtree()</kbd> |
| <kbd>\_\_getitem\_\_()</kbd><br /><kbd>fs[path]</kbd> | 获取路径对应的 <kbd>dupan.DuPanPath</kbd> 对象 | <kbd>as_path()</kbd> |
| <kbd>\_\_iter\_\_()</kbd><br /><kbd>iter(fs)</kbd> | 遍历目录,获取 <kbd>dupan.DuPanPath</kbd> 对象的迭代器 | <kbd>iter(max_depth=-1)</kbd> |
| <kbd>\_\_itruediv\_\_()</kbd><br /><kbd>fs /= path</kbd> | 切换当前工作目录 | <kbd>chdir()</kbd> |
| <kbd>\_\_len\_\_()</kbd><br /><kbd>len(fs)</kbd> | 获取当前目录的直属文件和目录数 | |
| <kbd>\_\_repr\_\_()</kbd><br /><kbd>repr(fs)</kbd> | 获取对象的字符串表示 | |
| <kbd>\_\_setitem\_\_()</kbd><br /><kbd>fs[path] = data</kbd> | 替换文件或上传目录等 | <kbd>touch()</kbd><br /><kbd>upload()</kbd><br /><kbd>upload_tree()</kbd><br /><kbd>write_bytes()</kbd><br /><kbd>write_text()</kbd> |
| <kbd>abspath()</kbd> | 获取绝对路径 | <kbd>[posixpath.abspath](https://docs.python.org/3/library/os.path.html#os.path.abspath)</kbd> |
| <kbd>as_path()</kbd> | 获取路径对应的 <kbd>dupan.DuPanPath</kbd> 对象 | |
| <kbd>attr()</kbd> | 获取文件或目录的属性 | |
| <kbd>chdir()</kbd><br /><kbd>cd()</kbd> | 切换当前工作目录 | <kbd>[os.chdir](https://docs.python.org/3/library/os.html#os.chdir)</kbd> |
| <kbd>copy()</kbd><br /><kbd>cp()</kbd> | 复制文件 | <kbd>[shutil.copy](https://docs.python.org/3/library/shutil.html#shutil.copy)</kbd> |
| <kbd>copytree()</kbd> | 复制文件或目录 | <kbd>[shutil.copytree](https://docs.python.org/3/library/shutil.html#shutil.copytree)</kbd> |
| <kbd>download()</kbd> | 下载文件 | <kbd style="background-color: red; color: white">暂不可用</kbd> |
| <kbd>download_tree()</kbd> | 下载文件或目录 | <kbd style="background-color: red; color: white">暂不可用</kbd> |
| <kbd>exists()</kbd> | 判断文件或目录是否存在 | <kbd>[posixpath.exists](https://docs.python.org/3/library/os.path.html#os.path.exists)</kbd> |
| <kbd>getcwd()</kbd><br /><kbd>pwd()</kbd> | 获取当前工作目录的路径 | <kbd>[os.getcwd](https://docs.python.org/3/library/os.html#os.getcwd)</kbd> |
| <kbd>get_url()</kbd> | 获取文件的下载链接 | |
| <kbd>glob()</kbd> | 遍历目录并用通配符模式筛选 | <kbd>[glob.iglob](https://docs.python.org/3/library/glob.html#glob.iglob)</kbd><br /><kbd>[pathlib.Path.glob](https://docs.python.org/3/library/pathlib.html#pathlib.Path.glob)</kbd> |
| <kbd>isdir()</kbd> | 判断是否存在且是目录 | <kbd>[posixpath.isdir](https://docs.python.org/3/library/os.path.html#os.path.isdir)</kbd> |
| <kbd>isfile()</kbd> | 判断是否存在且是文件 | <kbd>[posixpath.isfile](https://docs.python.org/3/library/os.path.html#os.path.isfile)</kbd> |
| <kbd>is_empty()</kbd> | 判断是否不存在、空文件或空目录 | |
| <kbd>iter()</kbd> | 遍历目录,获取 <kbd>dupan.DuPanPath</kbd> 对象的迭代器 | |
| <kbd>iterdir()</kbd> | 迭代目录,获取 <kbd>dupan.DuPanPath</kbd> 对象的迭代器 | <kbd>[pathlib.Path.iterdir](https://docs.python.org/3/library/pathlib.html#pathlib.Path.iterdir)</kbd> |
| <kbd>listdir()</kbd><br /><kbd>ls()</kbd> | 罗列目录,获取文件名列表 | <kbd>[os.listdir](https://docs.python.org/3/library/os.html#os.listdir)</kbd> |
| <kbd>listdir_attr()</kbd><br /><kbd>la()</kbd> | 罗列目录,获取文件属性 <kbd>dict</kbd> 列表 | |
| <kbd>listdir_path()</kbd><br /><kbd>ll()</kbd> | 罗列目录,获取 <kbd>dupan.DuPanPath</kbd> 对象列表 | |
| <kbd>makedirs()</kbd> | 创建多级的空目录 | <kbd>[os.makedirs](https://docs.python.org/3/library/os.html#os.makedirs)</kbd> |
| <kbd>mkdir()</kbd> | 创建空目录 | <kbd>[os.mkdir](https://docs.python.org/3/library/os.html#os.mkdir)</kbd> |
| <kbd>move()</kbd><br /><kbd>mv()</kbd> | 对文件或目录进行改名或移动,如果目标路径存在且是目录,则把文件移动到其中(但是目录中有同名的文件或目录,还是会报错) | <kbd>[shutil.move](https://docs.python.org/3/library/shutil.html#shutil.move)</kbd> |
| <kbd>open()</kbd> | 打开文件(只支持读,如果要写,请用 <kbd>write_bytes</kbd> 或 <kbd>upload</kbd> 替代) | <kbd>[open](https://docs.python.org/3/library/functions.html#open)</kbd><br /><kbd>[io.open](https://docs.python.org/3/library/io.html#io.open)</kbd><br /><kbd style="background-color: red; color: white">暂不可用</kbd> |
| <kbd>read_bytes()</kbd> | 读取文件为二进制 | <kbd>[pathlib.Path.read_bytes](https://docs.python.org/3/library/pathlib.html#pathlib.Path.read_bytes)</kbd><br /><kbd style="background-color: red; color: white">暂不可用</kbd> |
| <kbd>read_bytes_range()</kbd> | 读取文件为二进制 | <kbd style="background-color: red; color: white">暂不可用</kbd> |
| <kbd>read_block()</kbd> | 读取文件为二进制 | <kbd style="background-color: red; color: white">暂不可用</kbd> |
| <kbd>read_text()</kbd> | 读取文件为文本 | <kbd>[pathlib.Path.read_text](https://docs.python.org/3/library/pathlib.html#pathlib.Path.read_text)</kbd><br /><kbd style="background-color: red; color: white">暂不可用</kbd> |
| <kbd>remove()</kbd><br /><kbd>rm()</kbd> | 删除文件 | <kbd>[os.remove](https://docs.python.org/3/library/os.html#os.remove)</kbd> |
| <kbd>removedirs()</kbd> | (自底向上地)删除多级的空目录 | <kbd>[os.removedirs](https://docs.python.org/3/library/os.html#os.removedirs)</kbd> |
| <kbd>rename()</kbd> | 对文件或目录进行改名或移动 | <kbd>[os.rename](https://docs.python.org/3/library/os.html#os.rename)</kbd> |
| <kbd>renames()</kbd> | 对文件或目录进行改名或移动,然后对原来所在目录执行 <kbd>removedirs</kbd> | <kbd>[os.renames](https://docs.python.org/3/library/os.html#os.renames)</kbd> |
| <kbd>replace()</kbd> | 对文件或目录进行改名或移动,并且如果原来路径上是文件,目标路径上也存在同名文件,则会先把后者删除 | <kbd>[os.replace](https://docs.python.org/3/library/os.html#os.replace)</kbd> |
| <kbd>rglob()</kbd> |遍历目录并用通配符模式筛选 | <kbd>[pathlib.Path.rglob](https://docs.python.org/3/library/pathlib.html#pathlib.Path.rglob)</kbd> |
| <kbd>rmdir()</kbd> | 删除空目录 | <kbd>[os.rmdir](https://docs.python.org/3/library/os.html#os.rmdir)</kbd> |
| <kbd>rmtree()</kbd> | 删除文件或目录 | <kbd>[shutil.rmtree](https://docs.python.org/3/library/shutil.html#shutil.rmtree)</kbd> |
| <kbd>scandir()</kbd> | 迭代目录,获取 <kbd>dupan.DuPanPath</kbd> 对象的迭代器 | <kbd>[os.scandir](https://docs.python.org/3/library/os.html#os.scandir)</kbd> |
| <kbd>stat()</kbd> | 获取文件状态 <kbd>[os.stat_result](https://docs.python.org/3/library/os.html#os.stat_result)</kbd> 信息 | <kbd>[os.stat](https://docs.python.org/3/library/os.html#os.stat)</kbd> |
| <kbd>touch()</kbd> | 访问路径,如果不存在则新建空文件 | <kbd>[pathlib.Path.touch](https://docs.python.org/3/library/pathlib.html#pathlib.Path.touch)</kbd><br /><kbd style="background-color: red; color: white">暂不可用</kbd> |
| <kbd>upload()</kbd> | 上传文件 | <kbd style="background-color: red; color: white">暂不可用</kbd> |
| <kbd>upload_tree()</kbd> | 上传目录 | <kbd style="background-color: red; color: white">暂不可用</kbd> |
| <kbd>unlink()</kbd> | 删除文件 | <kbd>[os.unlink](https://docs.python.org/3/library/os.html#os.unlink)</kbd> |
| <kbd>walk()</kbd> | 遍历目录,获取文件名列表 | <kbd>[os.walk](https://docs.python.org/3/library/os.html#os.walk)</kbd> |
| <kbd>walk_attr()</kbd> | 遍历目录,获取文件属性 <kbd>dict</kbd> 列表 | |
| <kbd>walk_path()</kbd> | 遍历目录,获取 <kbd>dupan.DuPanPath</kbd> 对象列表 | |
| <kbd>write_bytes()</kbd> | 向文件写入二进制 | <kbd>[pathlib.Path.write_bytes](https://docs.python.org/3/library/pathlib.html#pathlib.Path.write_bytes)</kbd><br /><kbd style="background-color: red; color: white">暂不可用</kbd> |
| <kbd>write_text()</kbd> | 向文件写入文本 | <kbd>[pathlib.Path.write_text](https://docs.python.org/3/library/pathlib.html#pathlib.Path.write_text)</kbd><br /><kbd style="background-color: red; color: white">暂不可用</kbd> |
<kbd>dupan.DuPanPath</kbd> 实现了二次封装,从路径的角度来进行操作。
### 3. 遍历文件系统和查找文件
#### 1. 获取当前目录下所有 .mkv 文件的 url
**第 1 种方法,使用** <kbd>iter</kbd>,返回 <kbd>dupan.DuPanPath</kbd> 对象的迭代器
```python
for path in fs.iter(max_depth=-1):
if path.name.endswith(".mkv"):
print(path.url)
```
**第 2 种方法,使用** <kbd>glob</kbd>,参考 <kbd>pathlib.Path.glob</kbd> 和 <kbd>glob.iglob</kbd>,使用通配符查找
```python
for path in fs.glob("**/*.mkv"):
print(path.url)
```
**第 3 种方法,使用** <kbd>rglob</kbd>,参考 <kbd>pathlib.Path.rglob</kbd>
```python
for path in fs.rglob("*.mkv"):
print(path.url)
```
## 文档
> 正在编写中
Raw data
{
"_id": null,
"home_page": "https://github.com/ChenyangGao/web-mount-packs/tree/main/python-dupan-client",
"name": "python-dupan",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.10",
"maintainer_email": null,
"keywords": "nas, dupan, \u767e\u5ea6\u7f51\u76d8",
"author": "ChenyangGao",
"author_email": "wosiwujm@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/5c/c8/c7bbfa2a7150362b6a821ebb9eecc41a551c97b553b778bbfbc8980ee8b3/python_dupan-0.0.1.3.8.tar.gz",
"platform": null,
"description": "# \u767e\u5ea6\u7f51\u76d8 Web API \u7684 Python \u5c01\u88c5\n\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/python-dupan)\n![PyPI - Version](https://img.shields.io/pypi/v/python-dupan)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/python-dupan)\n![PyPI - Format](https://img.shields.io/pypi/format/python-dupan)\n![PyPI - Status](https://img.shields.io/pypi/status/python-dupan)\n\n## \u5b89\u88c5\n\n\u901a\u8fc7 [pypi](https://pypi.org/project/python-dupan/)\n\n```console\npip install -U python-dupan\n```\n\n## \u5165\u95e8\u4ecb\u7ecd\n\n### 1. \u5bfc\u5165\u6a21\u5757\u548c\u521b\u5efa\u5b9e\u4f8b\n\n**\u5bfc\u5165\u6a21\u5757**\n\n```python\nfrom dupan import DuPanClient, DuPanFileSystem\n```\n\n**\u521b\u5efa\u5ba2\u6237\u7aef\u5bf9\u8c61\uff0c\u9700\u8981\u4f20\u5165 <kbd>cookie</kbd>\uff0c\u5982\u679c\u4e0d\u4f20\u6216\u8005 <kbd>cookie</kbd> \u5931\u6548\uff0c\u5219\u9700\u8981\u626b\u7801\u767b\u5f55**\n\n```python\ncookie = \"BDUSS=...;STOKEN=...\"\nclient = DuPanClient(cookie)\n```\n\n**\u521b\u5efa\u6587\u4ef6\u7cfb\u7edf\u5bf9\u8c61**\n\n```python\nfs = DuPanFileSystem(client)\n```\n\n\u6216\u8005\u76f4\u63a5\u5728 <kbd>client</kbd> \u4e0a\u5c31\u53ef\u83b7\u53d6\u6587\u4ef6\u7cfb\u7edf\u5bf9\u8c61\n\n```python\nfs = client.fs\n```\n\n\u6216\u8005\u76f4\u63a5\u7528 <kbd>DuPanFileSystem</kbd> \u767b\u5f55\n\n```python\nfs = DuPanFileSystem.login(cookie)\n```\n\n### 2. \u64cd\u4f5c\u7f51\u76d8\u4f7f\u7528 Python \u5f0f\u7684\u6587\u4ef6\u7cfb\u7edf\u65b9\u6cd5\n\n\u6587\u4ef6\u7cfb\u7edf\u5bf9\u8c61\u7684\u65b9\u6cd5\uff0c\u8bbe\u8ba1\u548c\u884c\u4e3a\u53c2\u8003\u4e86 <kbd>[os](https://docs.python.org/3/library/os.html)</kbd>\u3001<kbd>[posixpath](https://docs.python.org/3/library/os.path.html)</kbd>\u3001<kbd>[pathlib.Path](https://docs.python.org/3/library/pathlib.html)</kbd> \u548c <kbd>[shutil](https://docs.python.org/3/library/shutil.html)</kbd> \u7b49\u6a21\u5757\u3002\n\n<kbd>dupan.DuPanFileSystem</kbd> \u5b9e\u73b0\u4e86\u8bfb\u5199\u7684\u6587\u4ef6\u7cfb\u7edf\u65b9\u6cd5\u3002\n\n\n| \u65b9\u6cd5 | \u8bf4\u660e | \u53c2\u8003|\n| --- | --- | --- |\n| <kbd>\\_\\_contains\\_\\_()</kbd><br /><kbd>path in fs</kbd> | \u5224\u65ad\u8def\u5f84\u662f\u5426\u5b58\u5728 | <kbd>exists()</kbd> |\n| <kbd>\\_\\_delitem\\_\\_()</kbd><br /><kbd>del fs[path]</kbd> | \u5220\u9664\u6587\u4ef6\u6216\u76ee\u5f55 | <kbd>rmtree()</kbd> |\n| <kbd>\\_\\_getitem\\_\\_()</kbd><br /><kbd>fs[path]</kbd> | \u83b7\u53d6\u8def\u5f84\u5bf9\u5e94\u7684 <kbd>dupan.DuPanPath</kbd> \u5bf9\u8c61 | <kbd>as_path()</kbd> |\n| <kbd>\\_\\_iter\\_\\_()</kbd><br /><kbd>iter(fs)</kbd> | \u904d\u5386\u76ee\u5f55\uff0c\u83b7\u53d6 <kbd>dupan.DuPanPath</kbd> \u5bf9\u8c61\u7684\u8fed\u4ee3\u5668 | <kbd>iter(max_depth=-1)</kbd> |\n| <kbd>\\_\\_itruediv\\_\\_()</kbd><br /><kbd>fs /= path</kbd> | \u5207\u6362\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55 | <kbd>chdir()</kbd> |\n| <kbd>\\_\\_len\\_\\_()</kbd><br /><kbd>len(fs)</kbd> | \u83b7\u53d6\u5f53\u524d\u76ee\u5f55\u7684\u76f4\u5c5e\u6587\u4ef6\u548c\u76ee\u5f55\u6570 | |\n| <kbd>\\_\\_repr\\_\\_()</kbd><br /><kbd>repr(fs)</kbd> | \u83b7\u53d6\u5bf9\u8c61\u7684\u5b57\u7b26\u4e32\u8868\u793a | |\n| <kbd>\\_\\_setitem\\_\\_()</kbd><br /><kbd>fs[path] = data</kbd> | \u66ff\u6362\u6587\u4ef6\u6216\u4e0a\u4f20\u76ee\u5f55\u7b49 | <kbd>touch()</kbd><br /><kbd>upload()</kbd><br /><kbd>upload_tree()</kbd><br /><kbd>write_bytes()</kbd><br /><kbd>write_text()</kbd> |\n| <kbd>abspath()</kbd> | \u83b7\u53d6\u7edd\u5bf9\u8def\u5f84 | <kbd>[posixpath.abspath](https://docs.python.org/3/library/os.path.html#os.path.abspath)</kbd> |\n| <kbd>as_path()</kbd> | \u83b7\u53d6\u8def\u5f84\u5bf9\u5e94\u7684 <kbd>dupan.DuPanPath</kbd> \u5bf9\u8c61 | |\n| <kbd>attr()</kbd> | \u83b7\u53d6\u6587\u4ef6\u6216\u76ee\u5f55\u7684\u5c5e\u6027 | |\n| <kbd>chdir()</kbd><br /><kbd>cd()</kbd> | \u5207\u6362\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55 | <kbd>[os.chdir](https://docs.python.org/3/library/os.html#os.chdir)</kbd> |\n| <kbd>copy()</kbd><br /><kbd>cp()</kbd> | \u590d\u5236\u6587\u4ef6 | <kbd>[shutil.copy](https://docs.python.org/3/library/shutil.html#shutil.copy)</kbd> |\n| <kbd>copytree()</kbd> | \u590d\u5236\u6587\u4ef6\u6216\u76ee\u5f55 | <kbd>[shutil.copytree](https://docs.python.org/3/library/shutil.html#shutil.copytree)</kbd> |\n| <kbd>download()</kbd> | \u4e0b\u8f7d\u6587\u4ef6 | <kbd style=\"background-color: red; color: white\">\u6682\u4e0d\u53ef\u7528</kbd> |\n| <kbd>download_tree()</kbd> | \u4e0b\u8f7d\u6587\u4ef6\u6216\u76ee\u5f55 | <kbd style=\"background-color: red; color: white\">\u6682\u4e0d\u53ef\u7528</kbd> |\n| <kbd>exists()</kbd> | \u5224\u65ad\u6587\u4ef6\u6216\u76ee\u5f55\u662f\u5426\u5b58\u5728 | <kbd>[posixpath.exists](https://docs.python.org/3/library/os.path.html#os.path.exists)</kbd> |\n| <kbd>getcwd()</kbd><br /><kbd>pwd()</kbd> | \u83b7\u53d6\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u7684\u8def\u5f84 | <kbd>[os.getcwd](https://docs.python.org/3/library/os.html#os.getcwd)</kbd> |\n| <kbd>get_url()</kbd> | \u83b7\u53d6\u6587\u4ef6\u7684\u4e0b\u8f7d\u94fe\u63a5 | |\n| <kbd>glob()</kbd> | \u904d\u5386\u76ee\u5f55\u5e76\u7528\u901a\u914d\u7b26\u6a21\u5f0f\u7b5b\u9009 | <kbd>[glob.iglob](https://docs.python.org/3/library/glob.html#glob.iglob)</kbd><br /><kbd>[pathlib.Path.glob](https://docs.python.org/3/library/pathlib.html#pathlib.Path.glob)</kbd> |\n| <kbd>isdir()</kbd> | \u5224\u65ad\u662f\u5426\u5b58\u5728\u4e14\u662f\u76ee\u5f55 | <kbd>[posixpath.isdir](https://docs.python.org/3/library/os.path.html#os.path.isdir)</kbd> |\n| <kbd>isfile()</kbd> | \u5224\u65ad\u662f\u5426\u5b58\u5728\u4e14\u662f\u6587\u4ef6 | <kbd>[posixpath.isfile](https://docs.python.org/3/library/os.path.html#os.path.isfile)</kbd> |\n| <kbd>is_empty()</kbd> | \u5224\u65ad\u662f\u5426\u4e0d\u5b58\u5728\u3001\u7a7a\u6587\u4ef6\u6216\u7a7a\u76ee\u5f55 | |\n| <kbd>iter()</kbd> | \u904d\u5386\u76ee\u5f55\uff0c\u83b7\u53d6 <kbd>dupan.DuPanPath</kbd> \u5bf9\u8c61\u7684\u8fed\u4ee3\u5668 | |\n| <kbd>iterdir()</kbd> | \u8fed\u4ee3\u76ee\u5f55\uff0c\u83b7\u53d6 <kbd>dupan.DuPanPath</kbd> \u5bf9\u8c61\u7684\u8fed\u4ee3\u5668 | <kbd>[pathlib.Path.iterdir](https://docs.python.org/3/library/pathlib.html#pathlib.Path.iterdir)</kbd> |\n| <kbd>listdir()</kbd><br /><kbd>ls()</kbd> | \u7f57\u5217\u76ee\u5f55\uff0c\u83b7\u53d6\u6587\u4ef6\u540d\u5217\u8868 | <kbd>[os.listdir](https://docs.python.org/3/library/os.html#os.listdir)</kbd> |\n| <kbd>listdir_attr()</kbd><br /><kbd>la()</kbd> | \u7f57\u5217\u76ee\u5f55\uff0c\u83b7\u53d6\u6587\u4ef6\u5c5e\u6027 <kbd>dict</kbd> \u5217\u8868 | |\n| <kbd>listdir_path()</kbd><br /><kbd>ll()</kbd> | \u7f57\u5217\u76ee\u5f55\uff0c\u83b7\u53d6 <kbd>dupan.DuPanPath</kbd> \u5bf9\u8c61\u5217\u8868 | |\n| <kbd>makedirs()</kbd> | \u521b\u5efa\u591a\u7ea7\u7684\u7a7a\u76ee\u5f55 | <kbd>[os.makedirs](https://docs.python.org/3/library/os.html#os.makedirs)</kbd> |\n| <kbd>mkdir()</kbd> | \u521b\u5efa\u7a7a\u76ee\u5f55 | <kbd>[os.mkdir](https://docs.python.org/3/library/os.html#os.mkdir)</kbd> |\n| <kbd>move()</kbd><br /><kbd>mv()</kbd> | \u5bf9\u6587\u4ef6\u6216\u76ee\u5f55\u8fdb\u884c\u6539\u540d\u6216\u79fb\u52a8\uff0c\u5982\u679c\u76ee\u6807\u8def\u5f84\u5b58\u5728\u4e14\u662f\u76ee\u5f55\uff0c\u5219\u628a\u6587\u4ef6\u79fb\u52a8\u5230\u5176\u4e2d\uff08\u4f46\u662f\u76ee\u5f55\u4e2d\u6709\u540c\u540d\u7684\u6587\u4ef6\u6216\u76ee\u5f55\uff0c\u8fd8\u662f\u4f1a\u62a5\u9519\uff09 | <kbd>[shutil.move](https://docs.python.org/3/library/shutil.html#shutil.move)</kbd> |\n| <kbd>open()</kbd> | \u6253\u5f00\u6587\u4ef6\uff08\u53ea\u652f\u6301\u8bfb\uff0c\u5982\u679c\u8981\u5199\uff0c\u8bf7\u7528 <kbd>write_bytes</kbd> \u6216 <kbd>upload</kbd> \u66ff\u4ee3\uff09 | <kbd>[open](https://docs.python.org/3/library/functions.html#open)</kbd><br /><kbd>[io.open](https://docs.python.org/3/library/io.html#io.open)</kbd><br /><kbd style=\"background-color: red; color: white\">\u6682\u4e0d\u53ef\u7528</kbd> |\n| <kbd>read_bytes()</kbd> | \u8bfb\u53d6\u6587\u4ef6\u4e3a\u4e8c\u8fdb\u5236 | <kbd>[pathlib.Path.read_bytes](https://docs.python.org/3/library/pathlib.html#pathlib.Path.read_bytes)</kbd><br /><kbd style=\"background-color: red; color: white\">\u6682\u4e0d\u53ef\u7528</kbd> |\n| <kbd>read_bytes_range()</kbd> | \u8bfb\u53d6\u6587\u4ef6\u4e3a\u4e8c\u8fdb\u5236 | <kbd style=\"background-color: red; color: white\">\u6682\u4e0d\u53ef\u7528</kbd> |\n| <kbd>read_block()</kbd> | \u8bfb\u53d6\u6587\u4ef6\u4e3a\u4e8c\u8fdb\u5236 | <kbd style=\"background-color: red; color: white\">\u6682\u4e0d\u53ef\u7528</kbd> |\n| <kbd>read_text()</kbd> | \u8bfb\u53d6\u6587\u4ef6\u4e3a\u6587\u672c | <kbd>[pathlib.Path.read_text](https://docs.python.org/3/library/pathlib.html#pathlib.Path.read_text)</kbd><br /><kbd style=\"background-color: red; color: white\">\u6682\u4e0d\u53ef\u7528</kbd> |\n| <kbd>remove()</kbd><br /><kbd>rm()</kbd> | \u5220\u9664\u6587\u4ef6 | <kbd>[os.remove](https://docs.python.org/3/library/os.html#os.remove)</kbd> |\n| <kbd>removedirs()</kbd> | \uff08\u81ea\u5e95\u5411\u4e0a\u5730\uff09\u5220\u9664\u591a\u7ea7\u7684\u7a7a\u76ee\u5f55 | <kbd>[os.removedirs](https://docs.python.org/3/library/os.html#os.removedirs)</kbd> |\n| <kbd>rename()</kbd> | \u5bf9\u6587\u4ef6\u6216\u76ee\u5f55\u8fdb\u884c\u6539\u540d\u6216\u79fb\u52a8 | <kbd>[os.rename](https://docs.python.org/3/library/os.html#os.rename)</kbd> |\n| <kbd>renames()</kbd> | \u5bf9\u6587\u4ef6\u6216\u76ee\u5f55\u8fdb\u884c\u6539\u540d\u6216\u79fb\u52a8\uff0c\u7136\u540e\u5bf9\u539f\u6765\u6240\u5728\u76ee\u5f55\u6267\u884c <kbd>removedirs</kbd> | <kbd>[os.renames](https://docs.python.org/3/library/os.html#os.renames)</kbd> |\n| <kbd>replace()</kbd> | \u5bf9\u6587\u4ef6\u6216\u76ee\u5f55\u8fdb\u884c\u6539\u540d\u6216\u79fb\u52a8\uff0c\u5e76\u4e14\u5982\u679c\u539f\u6765\u8def\u5f84\u4e0a\u662f\u6587\u4ef6\uff0c\u76ee\u6807\u8def\u5f84\u4e0a\u4e5f\u5b58\u5728\u540c\u540d\u6587\u4ef6\uff0c\u5219\u4f1a\u5148\u628a\u540e\u8005\u5220\u9664 | <kbd>[os.replace](https://docs.python.org/3/library/os.html#os.replace)</kbd> |\n| <kbd>rglob()</kbd> |\u904d\u5386\u76ee\u5f55\u5e76\u7528\u901a\u914d\u7b26\u6a21\u5f0f\u7b5b\u9009 | <kbd>[pathlib.Path.rglob](https://docs.python.org/3/library/pathlib.html#pathlib.Path.rglob)</kbd> |\n| <kbd>rmdir()</kbd> | \u5220\u9664\u7a7a\u76ee\u5f55 | <kbd>[os.rmdir](https://docs.python.org/3/library/os.html#os.rmdir)</kbd> |\n| <kbd>rmtree()</kbd> | \u5220\u9664\u6587\u4ef6\u6216\u76ee\u5f55 | <kbd>[shutil.rmtree](https://docs.python.org/3/library/shutil.html#shutil.rmtree)</kbd> |\n| <kbd>scandir()</kbd> | \u8fed\u4ee3\u76ee\u5f55\uff0c\u83b7\u53d6 <kbd>dupan.DuPanPath</kbd> \u5bf9\u8c61\u7684\u8fed\u4ee3\u5668 | <kbd>[os.scandir](https://docs.python.org/3/library/os.html#os.scandir)</kbd> |\n| <kbd>stat()</kbd> | \u83b7\u53d6\u6587\u4ef6\u72b6\u6001 <kbd>[os.stat_result](https://docs.python.org/3/library/os.html#os.stat_result)</kbd> \u4fe1\u606f | <kbd>[os.stat](https://docs.python.org/3/library/os.html#os.stat)</kbd> |\n| <kbd>touch()</kbd> | \u8bbf\u95ee\u8def\u5f84\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u5219\u65b0\u5efa\u7a7a\u6587\u4ef6 | <kbd>[pathlib.Path.touch](https://docs.python.org/3/library/pathlib.html#pathlib.Path.touch)</kbd><br /><kbd style=\"background-color: red; color: white\">\u6682\u4e0d\u53ef\u7528</kbd> |\n| <kbd>upload()</kbd> | \u4e0a\u4f20\u6587\u4ef6 | <kbd style=\"background-color: red; color: white\">\u6682\u4e0d\u53ef\u7528</kbd> |\n| <kbd>upload_tree()</kbd> | \u4e0a\u4f20\u76ee\u5f55 | <kbd style=\"background-color: red; color: white\">\u6682\u4e0d\u53ef\u7528</kbd> |\n| <kbd>unlink()</kbd> | \u5220\u9664\u6587\u4ef6 | <kbd>[os.unlink](https://docs.python.org/3/library/os.html#os.unlink)</kbd> |\n| <kbd>walk()</kbd> | \u904d\u5386\u76ee\u5f55\uff0c\u83b7\u53d6\u6587\u4ef6\u540d\u5217\u8868 | <kbd>[os.walk](https://docs.python.org/3/library/os.html#os.walk)</kbd> |\n| <kbd>walk_attr()</kbd> | \u904d\u5386\u76ee\u5f55\uff0c\u83b7\u53d6\u6587\u4ef6\u5c5e\u6027 <kbd>dict</kbd> \u5217\u8868 | |\n| <kbd>walk_path()</kbd> | \u904d\u5386\u76ee\u5f55\uff0c\u83b7\u53d6 <kbd>dupan.DuPanPath</kbd> \u5bf9\u8c61\u5217\u8868 | |\n| <kbd>write_bytes()</kbd> | \u5411\u6587\u4ef6\u5199\u5165\u4e8c\u8fdb\u5236 | <kbd>[pathlib.Path.write_bytes](https://docs.python.org/3/library/pathlib.html#pathlib.Path.write_bytes)</kbd><br /><kbd style=\"background-color: red; color: white\">\u6682\u4e0d\u53ef\u7528</kbd> |\n| <kbd>write_text()</kbd> | \u5411\u6587\u4ef6\u5199\u5165\u6587\u672c | <kbd>[pathlib.Path.write_text](https://docs.python.org/3/library/pathlib.html#pathlib.Path.write_text)</kbd><br /><kbd style=\"background-color: red; color: white\">\u6682\u4e0d\u53ef\u7528</kbd> |\n\n<kbd>dupan.DuPanPath</kbd> \u5b9e\u73b0\u4e86\u4e8c\u6b21\u5c01\u88c5\uff0c\u4ece\u8def\u5f84\u7684\u89d2\u5ea6\u6765\u8fdb\u884c\u64cd\u4f5c\u3002\n\n### 3. \u904d\u5386\u6587\u4ef6\u7cfb\u7edf\u548c\u67e5\u627e\u6587\u4ef6\n\n#### 1. \u83b7\u53d6\u5f53\u524d\u76ee\u5f55\u4e0b\u6240\u6709 .mkv \u6587\u4ef6\u7684 url\n\n**\u7b2c 1 \u79cd\u65b9\u6cd5\uff0c\u4f7f\u7528** <kbd>iter</kbd>\uff0c\u8fd4\u56de <kbd>dupan.DuPanPath</kbd> \u5bf9\u8c61\u7684\u8fed\u4ee3\u5668\n\n```python\nfor path in fs.iter(max_depth=-1):\n if path.name.endswith(\".mkv\"):\n print(path.url)\n```\n\n**\u7b2c 2 \u79cd\u65b9\u6cd5\uff0c\u4f7f\u7528** <kbd>glob</kbd>\uff0c\u53c2\u8003 <kbd>pathlib.Path.glob</kbd> \u548c <kbd>glob.iglob</kbd>\uff0c\u4f7f\u7528\u901a\u914d\u7b26\u67e5\u627e\n\n```python\nfor path in fs.glob(\"**/*.mkv\"):\n print(path.url)\n```\n\n**\u7b2c 3 \u79cd\u65b9\u6cd5\uff0c\u4f7f\u7528** <kbd>rglob</kbd>\uff0c\u53c2\u8003 <kbd>pathlib.Path.rglob</kbd>\n\n```python\nfor path in fs.rglob(\"*.mkv\"):\n print(path.url)\n```\n\n## \u6587\u6863\n\n> \u6b63\u5728\u7f16\u5199\u4e2d\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python wrapper for `baidu webdisk <https://pan.baidu.com>`.",
"version": "0.0.1.3.8",
"project_urls": {
"Homepage": "https://github.com/ChenyangGao/web-mount-packs/tree/main/python-dupan-client",
"Repository": "https://github.com/ChenyangGao/web-mount-packs/tree/main/python-dupan-client"
},
"split_keywords": [
"nas",
" dupan",
" \u767e\u5ea6\u7f51\u76d8"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "41f5377834ad8b4ed3a1ed8f181f45229f9d56f4be64e7a76f7fd229194e2a63",
"md5": "f7cbcb53578ae56a5e993a90a3b028fc",
"sha256": "cd096e8765b06d1f95c1664673615f62ffbdf1015219b0781bce88e47de18c22"
},
"downloads": -1,
"filename": "python_dupan-0.0.1.3.8-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f7cbcb53578ae56a5e993a90a3b028fc",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.10",
"size": 33000,
"upload_time": "2024-05-20T04:54:58",
"upload_time_iso_8601": "2024-05-20T04:54:58.375156Z",
"url": "https://files.pythonhosted.org/packages/41/f5/377834ad8b4ed3a1ed8f181f45229f9d56f4be64e7a76f7fd229194e2a63/python_dupan-0.0.1.3.8-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5cc8c7bbfa2a7150362b6a821ebb9eecc41a551c97b553b778bbfbc8980ee8b3",
"md5": "e98fe8197b565f8d7cf3213cbec75ac8",
"sha256": "a9790fbdac2182a4c834eb663019089fc4995b5b1a109cd65cd8c2a265edfd90"
},
"downloads": -1,
"filename": "python_dupan-0.0.1.3.8.tar.gz",
"has_sig": false,
"md5_digest": "e98fe8197b565f8d7cf3213cbec75ac8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.10",
"size": 29861,
"upload_time": "2024-05-20T04:55:00",
"upload_time_iso_8601": "2024-05-20T04:55:00.939465Z",
"url": "https://files.pythonhosted.org/packages/5c/c8/c7bbfa2a7150362b6a821ebb9eecc41a551c97b553b778bbfbc8980ee8b3/python_dupan-0.0.1.3.8.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-20 04:55:00",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ChenyangGao",
"github_project": "web-mount-packs",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "python-dupan"
}