# fastdfs-client-python
![Python Versions](https://img.shields.io/pypi/pyversions/fastdfs-client)
[![LatestVersionInPypi](https://img.shields.io/pypi/v/fastdfs-client.svg?style=flat)](https://pypi.python.org/pypi/fastdfs-client)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
![Mypy coverage](https://img.shields.io/badge/mypy-100%25-green.svg)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/pre-commit/pre-commit/main.svg)](https://github.com/pre-commit/pre-commit)
[![GithubActionResult](https://github.com/waketzheng/asyncur/workflows/ci/badge.svg)](https://github.com/waketzheng/asyncur/actions?query=workflow:ci)
FastDFS Python client
*Manual pass upload test with fastdfs v6.12.1*
**English** | [中文](./README.zh.md)
## Motivation
Base on:
- [fastdfs-client-py3 1.0.0](https://pypi.org/project/fastdfs-client-py3/)
Fixes:
- TypeError:
```
Traceback (most recent call last):
File "~/trying/something/upload.py", line 4, in <module>
client = Fdfs_client(tracker_conf_path)
File "~/trying/something/venv/lib/python3.10/site-packages/fdfs_client/client.py", line 52, in __init__
self.tracker_pool = poolclass(**self.trackers)
TypeError: fdfs_client.connection.ConnectionPool() argument after ** must be a mapping, not str
```
- ResponseError
```
fdfs_client.exceptions.ResponseError: [-] Error: Tracker response length is invaild, expect: 40, actual: 70
```
## Requires
- Python3.9+ (No other dependence)
For Python3.8, use https://github.com/waketzheng/fastdfs-client-python/tree/1.0.1
## Install
```bash
pip install fastdfs-client
```
## Usage
```py
from fastdfs_client import FastdfsClient
client = FastdfsClient('/etc/fdfs/client.conf')
ret = client.upload_by_filename('test.txt')
print(ret)
```
- Response sample
```JSON
{
"Group name": "group1",
"Status": "Upload successed.",
"Remote file_id": "group1/M00/00/00/wKjzh0_xaR63RExnAAAaDqbNk5E1398.txt",
"Uploaded size": "6.0KB",
"Local file name": "test.txt",
"Storage IP": "192.168.243.133"
}
```
## Advance
- Upload as URL
```py
from pathlib import Path
p = Path('test.txt')
client = FastdfsClient(["dfs.waketzheng.top"])
url = client.upload_as_url(p.read_bytes(), p.suffix)
print(url)
# https://dfs.waketzheng.top/group1/M00/00/00/wKjzh0_xaR63RExnAAAaDqbNk5E1398.txt
```
- Download
```py
save_to = 'local.txt'
client.download_to_file(save_to, 'group1/M00/00/00/wKjzh0_xaR63RExnAAAaDqbNk5E1398.txt')
```
- Delete
```py
id_or_url = 'https://dfs.waketzheng.top/group1/M00/00/00/wKjzh0_xaR63RExnAAAaDqbNk5E1398.txt'
# id_or_url = 'group1/M00/00/00/wKjzh0_xaR63RExnAAAaDqbNk5E1398.txt'
client.delete_file(id_or_url)
```
## AsyncIO/Trio
- upload
```py
from pathlib import Path
from fastdfs_client import FastdfsClient
client = FastdfsClient(["dfs.waketzheng.top"])
p = Path('tests/test_async_client.py')
url = await client.upload(p.read_bytes(), p.suffix)
print(url)
# https://dfs.waketzheng.top/group1/M00/00/00/xxx.py
```
- delete
```py
url = 'https://dfs.waketzheng.top/group1/M00/00/00/xxx.py'
resp = await client.delete(url)
print(resp)
# ('Delete file successed.', b'group1/M00/00/1B/eE0vIWaU9kyAVILJAAHM-px7j44359.py', b'120.77.47.33')
```
Raw data
{
"_id": null,
"home_page": "https://github.com/waketzheng/fastdfs-client-python",
"name": "fastdfs-client",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": null,
"author": "Waket Zheng",
"author_email": "waketzheng@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/02/e8/f3fdbc46a7dec7529bac80917d7d35f1b1b5926dd9f5a69eeb0f81aebac6/fastdfs_client-1.2.2.tar.gz",
"platform": null,
"description": "# fastdfs-client-python\n![Python Versions](https://img.shields.io/pypi/pyversions/fastdfs-client)\n[![LatestVersionInPypi](https://img.shields.io/pypi/v/fastdfs-client.svg?style=flat)](https://pypi.python.org/pypi/fastdfs-client)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n![Mypy coverage](https://img.shields.io/badge/mypy-100%25-green.svg)\n[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/pre-commit/pre-commit/main.svg)](https://github.com/pre-commit/pre-commit)\n[![GithubActionResult](https://github.com/waketzheng/asyncur/workflows/ci/badge.svg)](https://github.com/waketzheng/asyncur/actions?query=workflow:ci)\n\nFastDFS Python client\n\n*Manual pass upload test with fastdfs v6.12.1*\n\n**English** | [\u4e2d\u6587](./README.zh.md)\n\n## Motivation\n\nBase on:\n- [fastdfs-client-py3 1.0.0](https://pypi.org/project/fastdfs-client-py3/)\n\nFixes:\n- TypeError:\n```\nTraceback (most recent call last):\n File \"~/trying/something/upload.py\", line 4, in <module>\n client = Fdfs_client(tracker_conf_path)\n File \"~/trying/something/venv/lib/python3.10/site-packages/fdfs_client/client.py\", line 52, in __init__\n self.tracker_pool = poolclass(**self.trackers)\nTypeError: fdfs_client.connection.ConnectionPool() argument after ** must be a mapping, not str\n```\n- ResponseError\n```\nfdfs_client.exceptions.ResponseError: [-] Error: Tracker response length is invaild, expect: 40, actual: 70\n```\n\n## Requires\n\n- Python3.9+ (No other dependence)\n\nFor Python3.8, use https://github.com/waketzheng/fastdfs-client-python/tree/1.0.1\n\n## Install\n\n```bash\npip install fastdfs-client\n```\n\n## Usage\n\n```py\nfrom fastdfs_client import FastdfsClient\nclient = FastdfsClient('/etc/fdfs/client.conf')\nret = client.upload_by_filename('test.txt')\nprint(ret)\n```\n- Response sample\n```JSON\n{\n \"Group name\": \"group1\",\n \"Status\": \"Upload successed.\",\n \"Remote file_id\": \"group1/M00/00/00/wKjzh0_xaR63RExnAAAaDqbNk5E1398.txt\",\n \"Uploaded size\": \"6.0KB\",\n \"Local file name\": \"test.txt\",\n \"Storage IP\": \"192.168.243.133\"\n}\n```\n\n## Advance\n\n- Upload as URL\n\n```py\nfrom pathlib import Path\n\np = Path('test.txt')\nclient = FastdfsClient([\"dfs.waketzheng.top\"])\nurl = client.upload_as_url(p.read_bytes(), p.suffix)\nprint(url)\n# https://dfs.waketzheng.top/group1/M00/00/00/wKjzh0_xaR63RExnAAAaDqbNk5E1398.txt\n```\n- Download\n```py\nsave_to = 'local.txt'\nclient.download_to_file(save_to, 'group1/M00/00/00/wKjzh0_xaR63RExnAAAaDqbNk5E1398.txt')\n```\n- Delete\n```py\nid_or_url = 'https://dfs.waketzheng.top/group1/M00/00/00/wKjzh0_xaR63RExnAAAaDqbNk5E1398.txt'\n# id_or_url = 'group1/M00/00/00/wKjzh0_xaR63RExnAAAaDqbNk5E1398.txt'\nclient.delete_file(id_or_url)\n```\n\n## AsyncIO/Trio\n- upload\n```py\nfrom pathlib import Path\nfrom fastdfs_client import FastdfsClient\n\nclient = FastdfsClient([\"dfs.waketzheng.top\"])\np = Path('tests/test_async_client.py')\nurl = await client.upload(p.read_bytes(), p.suffix)\nprint(url)\n# https://dfs.waketzheng.top/group1/M00/00/00/xxx.py\n```\n- delete\n```py\nurl = 'https://dfs.waketzheng.top/group1/M00/00/00/xxx.py'\nresp = await client.delete(url)\nprint(resp)\n# ('Delete file successed.', b'group1/M00/00/1B/eE0vIWaU9kyAVILJAAHM-px7j44359.py', b'120.77.47.33')\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "Python Implement for FastDFS Client",
"version": "1.2.2",
"project_urls": {
"Homepage": "https://github.com/waketzheng/fastdfs-client-python",
"Repository": "https://github.com/waketzheng/fastdfs-client-python"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "688419ccc8538c00dca2c4315a18ebbc40189d81d3b09b1f216222d012c4ee74",
"md5": "f5cf1f1725e0d1cacf1af589f9e5abcc",
"sha256": "95e5da305d12ec7ef0999a5f0e18d350934206381a833af0072480136ba71549"
},
"downloads": -1,
"filename": "fastdfs_client-1.2.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f5cf1f1725e0d1cacf1af589f9e5abcc",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 38814,
"upload_time": "2024-11-13T15:39:26",
"upload_time_iso_8601": "2024-11-13T15:39:26.208917Z",
"url": "https://files.pythonhosted.org/packages/68/84/19ccc8538c00dca2c4315a18ebbc40189d81d3b09b1f216222d012c4ee74/fastdfs_client-1.2.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "02e8f3fdbc46a7dec7529bac80917d7d35f1b1b5926dd9f5a69eeb0f81aebac6",
"md5": "5514fc65e9fae3f7d472e7cb2c6d306e",
"sha256": "24280e6ed046b73c339601a46a6cdb61f5f37a0292786cd6efb0f2bd5a8acd81"
},
"downloads": -1,
"filename": "fastdfs_client-1.2.2.tar.gz",
"has_sig": false,
"md5_digest": "5514fc65e9fae3f7d472e7cb2c6d306e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 36938,
"upload_time": "2024-11-13T15:39:28",
"upload_time_iso_8601": "2024-11-13T15:39:28.553372Z",
"url": "https://files.pythonhosted.org/packages/02/e8/f3fdbc46a7dec7529bac80917d7d35f1b1b5926dd9f5a69eeb0f81aebac6/fastdfs_client-1.2.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-13 15:39:28",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "waketzheng",
"github_project": "fastdfs-client-python",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "fastdfs-client"
}