seaweedfs 的 python 模块(旧名称:weed-fs)
项目描述
蟒蛇杂草
它是什么?
seaweedfs 的 python 模块(https://github.com/chrislusf/seaweedfs.git)(旧名称是:weed-fs(https://code.google.com/p/weed-fs/))。
蟒蛇版本
- python3.7+
- 注意:对于旧的python2.7版本,使用master的branch:
v0.2.3-suited-for-python2.7或tag:(python2.7或)v0.2.3 - 注意:我们总是在文档中将 python 称为 python3.7+(也将 pip 称为 pip3),因为 python2 已被弃用。
- 信息:
- python3.6+ 支持 F-Strings:https ://www.python.org/dev/peps/pep-0498/
- python3.7 支持数据类
安装(pip 表示 pip3)
点安装蟒蛇杂草
或者,如果您想要最新版本:
点安装https://github.com/darkdarkfruit/python-weed/archive/master.zip
维基
例子
查看测试文件: test_weed.py
如何测试?
# Set up seaweedfs env
# Download weedfs(https://github.com/chrislusf/seaweedfs.git) binary and install it. (eg: v2.21)
> wget --quiet https://github.com/chrislusf/seaweedfs/releases/download/2.21/linux_amd64.tar.gz
# Start weedfs servers: master server, volume server, filer server.
> weed master # start master server in terminal 1, listens on port:9333 by default.
> weed volume -port=27000 # start volume server in terminal 2, listens on 27000
> weed filer -port=27100 # start filer server in terminal 3, listens on 27100
# start testing python-weed.
> pip install pytest
> pytest .
建造
python sdist
# or using make
make sdist
异步支持?
还没有。(待办事项:集成httpx:https ://github.com/encode/httpx )
海藻简介
SeaWeedFs 是一个简单且高度可扩展的分布式文件系统。有两个目标:
- 存储数十亿文件!
- 快速提供文件!
Weed-FS 不支持完整的 POSIX 文件系统语义,而是选择仅实现密钥文件映射。类似于“NoSQL”这个词,你可以称它为“NoFS”。请参阅(https://code.google.com/p/weed-fs/)中的详细信息
这是一个用于海藻的 python 模块。
使用 ipython(ipython3.9) 的示例日志
#-----------------------------------------------------------
In [1]: from weed.master import WeedMaster
In [2]: master = WeedMaster()
In [3]: master
Out[3]: <WeedMaster: 127.0.0.1:9333>
In [4]: master.
master.get_assign_key master.lookup master.url_base master.url_vacuum
master.get_status master.port master.url_lookup master.vacuum
master.host master.url_assign master.url_status
In [4]: master.get_assign_key()
Out[4]:
{u'count': 1,
u'fid': u'4,024a042190cca9',
u'publicUrl': u'127.0.0.1:8080',
u'url': u'127.0.0.1:8080'}
In [5]: master.lookup('4')
Out[5]: {u'locations': [{u'publicUrl': u'127.0.0.1:8080', u'url': u'127.0.0.1:8080'}]}
In [6]: master.get_status()
Out[6]:
{u'Topology': {u'DataCenters': [{u'Free': 93,
u'Max': 100,
u'Racks': [{u'DataNodes': [{u'Free': 93,
u'Max': 100,
u'PublicUrl': u'127.0.0.1:8080',
u'Url': u'127.0.0.1:8080',
u'Volumes': 7}],
u'Free': 93,
u'Max': 100}]}],
u'Free': 93,
u'Max': 100,
u'layouts': [{u'replication': u'000', u'writables': [2, 3, 5, 6, 7, 1, 4]}]},
u'Version': u'0.37'}
In [7]: volume = master.get_volume()
In [8]: volume
Out[8]: <WeedVolume: 127.0.0.1:8080>
In [9]: volume.get_status()
Out[9]:
{u'Version': u'0.37',
u'Volumes': [{u'DeleteCount': 0,
u'DeletedByteCount': 0,
u'FileCount': 1,
u'Id': 1,
u'ReadOnly': False,
u'RepType': u'000',
u'Size': 126481,
u'Version': 2},
{u'DeleteCount': 0,
u'DeletedByteCount': 0,
u'FileCount': 0,
u'Id': 2,
u'ReadOnly': False,
u'RepType': u'000',
u'Size': 0,
u'Version': 2},
{u'DeleteCount': 0,
u'DeletedByteCount': 0,
u'FileCount': 2,
u'Id': 3,
u'ReadOnly': False,
u'RepType': u'000',
u'Size': 438228,
u'Version': 2},
{u'DeleteCount': 0,
u'DeletedByteCount': 0,
u'FileCount': 0,
u'Id': 4,
u'ReadOnly': False,
u'RepType': u'000',
u'Size': 0,
u'Version': 2},
{u'DeleteCount': 0,
u'DeletedByteCount': 0,
u'FileCount': 0,
u'Id': 5,
u'ReadOnly': False,
u'RepType': u'000',
u'Size': 0,
u'Version': 2},
{u'DeleteCount': 0,
u'DeletedByteCount': 0,
u'FileCount': 0,
u'Id': 6,
u'ReadOnly': False,
u'RepType': u'000',
u'Size': 0,
u'Version': 2},
{u'DeleteCount': 0,
u'DeletedByteCount': 0,
u'FileCount': 0,
u'Id': 7,
u'ReadOnly': False,
u'RepType': u'000',
u'Size': 0,
u'Version': 2}]}
#-----------------------------------------------------------
#-----------------------------------------------------------
def omit_printing_content(d):
''' not showing large content on content '''
for k,v in d.items():
_v = v
if k == 'content' and v and len(v) > 10:
_v = v[:10] + '...(comment: size: %d, only show: 10). ' % len(v)
print(k,_v)
from weed import operation
wo = operation.WeedOperation()
# put
wor = wo.put('1.txt')
print(wor)
# get
wor = wo.get(wor.fid)
def omit_printing_content(d):
for k,v in d.items():
_v = v
if k == 'content' and v and len(v) > 10:
_v = v[:10] + '...(comment: size: %d, only show: 10). ' % len(v)
print(k,_v)
omit_printing_content(wor)
# delete
wor = wo.delete(wor.fid)
print(wor)
#-----------------------------------------------------------
#-----------------------------------------------------------
# crud aliases
wop = operation.WeedOperation()
#
# create
wor = wop.crud_create('1.txt')
print(wor)
# read
wor = wop.crud_read(wor.fid)
omit_printing_content(wor)
# update
wor = wop.crud_update('1.jpg', wor.fid)
print(wor)
wor = wop.crud_get(wor.fid)
wor = wop.crud_read(wor.fid)
omit_printing_content(wor)
# delete
wor = wop.delete(wor.fid)
print(wor)
#-----------------------------------------------------------
#-----------------------------------------------------------
# filer
from weed import filer
wf = filer.WeedFiler()
# put
f = wf.put('1.txt')
f = wf.put('1.txt', '/helloworld/')
print(f)
# get
f_get = wf.get('/helloworld/1.txt')
print(f_get)
omit_printing_content(f_get)
# delete
f_delete = wf.delete('/helloworld/1.txt')
print(f_delete)
#-----------------------------------------------------------