Skip to main content

Python Implement for FastDFS Client

Project description

fastdfs-client-python

Python Versions LatestVersionInPypi Ruff Mypy coverage pre-commit.ci status GithubActionResult

FastDFS Python client

Manual pass upload test with fastdfs v6.12.1

English | 中文

Motivation

Base on:

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

pip install fastdfs-client

Usage

from fastdfs_client import FastdfsClient
client = FastdfsClient('/etc/fdfs/client.conf')
ret = client.upload_by_filename('test.txt')
print(ret)
  • Response sample
{
    "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
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
save_to = 'local.txt'
client.download_to_file(save_to, 'group1/M00/00/00/wKjzh0_xaR63RExnAAAaDqbNk5E1398.txt')
  • Delete
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
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
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')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastdfs_client-1.2.3.tar.gz (36.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastdfs_client-1.2.3-py3-none-any.whl (38.8 kB view details)

Uploaded Python 3

File details

Details for the file fastdfs_client-1.2.3.tar.gz.

File metadata

  • Download URL: fastdfs_client-1.2.3.tar.gz
  • Upload date:
  • Size: 36.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.11.9 Darwin/20.6.0

File hashes

Hashes for fastdfs_client-1.2.3.tar.gz
Algorithm Hash digest
SHA256 abf0cfba9a19247b4ef16d2ec4a5baf4b1695fefd89b8f36c8a713e0fa752df1
MD5 f25845ae9049009d390f41afa627d11e
BLAKE2b-256 a79187e3c3e9260090f7a06b935325cab524f8dd75548f406706d4a727482d54

See more details on using hashes here.

File details

Details for the file fastdfs_client-1.2.3-py3-none-any.whl.

File metadata

  • Download URL: fastdfs_client-1.2.3-py3-none-any.whl
  • Upload date:
  • Size: 38.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.11.9 Darwin/20.6.0

File hashes

Hashes for fastdfs_client-1.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a728ad71520304fbc83db11ca1eed610f1c02a4b77786c44b99b698d43e3c175
MD5 690905140e8e29e1a8ce5ffb9ad659d2
BLAKE2b-256 3424914845bc3212669d3347d54924afc48740b4eb01391435e01061405809e4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page