Giter VIP home page Giter VIP logo

galaxy-fds-sdk-python's Introduction

简介

Galaxy FDS SDK Python封装了FDS的API,用户安装SDK后,可以非常容易地调用FDS提供的接口。

安装

安装pyhon-pip后,执行pip install galaxy-fds-sdk即可。

也可以在requirements.txt中写上galaxy-fds-sdk>=1.4.31

使用

使用前,内网用户需要在小米融合云官网得到应用的AccessKey和SecretKey,外网生态链用户则需要联系小米生态云得到应用的AccessKey和SecretKey。

创建Bucket

from fds import GalaxyFDSClient, GalaxyFDSClientException, FDSClientConfiguration
# FDSClientConfiguration 需要根据自己需要设置
client = GalaxyFDSClient(
    access_key="ACCESS_KEY",
    access_secret="SECRET_KEY",
    config=FDSClientConfiguration(
        endpoint="xxxx-fds.api.xiaomi.net",
        enable_cdn_for_upload=False,
        enable_cdn_for_download=False,
    ),
)


try:
  client.create_bucket("bucket_name")
except GalaxyFDSClientException as e:
  print(e.message)

上传Object

client.put_object("bucket_name", "object_name", "value")

下载Object

client.get_object("bucket_name", "object_name")

删除Object

client.delete_object("bucket_name", "object_name")

删除Bucket

try:
  client.delete_bucket("bucket_name")
except GalaxyFDSClientException as e:
  print e.message

其他

更多API操作请参考示例代码、单元测试代码和文档。

命令行工具

fds提供两种命令行工具:高层的fdscli和底层的fds

fdscli命令行提供与aws s3类似的交互方式,主要是access, config, info, presigned, set-public, show-ttl, rb, mb, rm, ls, cp, sync 12个子命令。用户可以通过fdscli命令获取所有子命令名称,同时可以通过fdscli+子命令名称的方式,获取每个子命令具体使用方式.

Usage: fdscli [OPTIONS] COMMAND [ARGS]...

Options:
  --ak TEXT            Access Key ID
  --sk TEXT            Access Key Secret
  --endpoint TEXT      FDS Endpoint
  --cdn_download       Whether to download using cdn
  --https              Whether to download using https
  --timeout INTEGER    Client Timeout
  --part_size INTEGER  Part size when multipart uploading
  --help               Show this message and exit.

Commands:
  access      set the accessibility of resource
  config      config ak, sk, endpoint and so on
  cp          cp command do lots of things.
  info        display the configurations
  ls          list all buckets or objects in a bucket
  mb          create(make) a bucket
  presigned   presigned command generates presigned url for download project
  rb          delete(remove) a bucket
  rm          delete(remove) a object
  set-public  set the resource of fds public or not
  show-ttl    ttl command shows the lifecycle information of a bucket or a...
  sync        sync command syncs between (local directory and fds) (fds and...
>>> fdscli rb --help                       
Usage: fdscli rb [OPTIONS] FDS_URL

  delete(remove) a bucket

Options:
  -f, --force  Delete bucket although it is nonempty
  --help       Show this message and exit.

IMPORTANT: 在fdscli命令中,通过fds://开头表示FDS远程资源,例如fds://bucket_name/home/a.txt则表示,bucket name为bucket_name, object name是home/a.txt的资源。 在cp命令中,通过 fdscli cp a.txt fds://bucket_name/home/ 命令实现文件上传,通过fdscli cp fds://bucket_name/home/a.txt a.txt实现文件下载,通过fdscli cp fds://bucket_name/home/a.txt fds://bucket_name/home/b.txt实现CopyObject。

fds命令使用方式可以通过fds命令获取帮助

实现

HTTP请求

FDS服务端可以响应带签名认证的HTTP请求,我们使用了requests库发送和接收请求。相比原生的urlliburllib2,使用requests后代码更加高效和易读,这是相当成熟的类库,连AWS的Python SDK也是基于它来开发的。

签名

我们基于requestsAuthBase实现了FDS的签名认证算法。算法实现请参考FDS官方文档。

API

通过阅读FDS的API文档,我们实现了上传下载Object等接口。HTTP请求参数、Header等信息参见FDS官方文档。

开发者

本项目采用Python官方推荐的以来管理工具poetry来管理,poetry作用类似于maven,主要依赖myproject.toml这个管理文件。

开发者开发步骤:

  1. cd ${galaxy-fds-sdk-python},到工程目录
  2. poetry install,安装依赖
  3. poetry add ${dependency},例如:pipenv install flask安装依赖
  4. poetry shell,进入激活当前工程以来的python环境
  5. poetry publish --build 发布到pypi

参考资料

galaxy-fds-sdk-python's People

Contributors

hujianxin avatar lshangq avatar sdxshen avatar shenjiaqi avatar wuzesheng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

galaxy-fds-sdk-python's Issues

ubuntu14.04默认python版本pip install 安装抛出异常

异常日志: error in galaxy-fds-sdk setup command: 'install_requires' must be a string or list of strings containing valid project/version requirement specifiers
修改:
install_requires=[
'requests>=2.20.0',
'argcomplete>=1.4.1',
'fire',
'future; python_version<"3"'],
为:
install_requires=[
'requests>=2.20.0',
'argcomplete>=1.4.1',
'fire',
'future’,
'python_version<"3"'],
就好了。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.