python open api_Python openapi3包_程序模块 - PyPI - Python中文网

作为客户使用

这个库还可以作为任意OpenAPI 3的交互客户机

规格。例如,使用Linode’s OpenAPI 3 Specification作为参考:from openapi3 import OpenAPI

# load the spec file and read the yaml

with open('openapi.yaml') as f:

spec = yaml.safe_load(f.read())

# parse the spec into python - this will raise if the spec is invalid

api = OpenAPI(spec)

# call operations and receive result models

regions = api.call_getRegions()

# authenticate using a securityScheme defined in the spec's components.securtiySchemes

api.authenticate('personalAccessToken', my_token)

# call an operation that requires authentication

linodes = api.call_getLinodeInstances()

# call an opertaion with parameters

linode = api.call_getLinodeInstance(parameters={"linodeId": 123})

# the models returns are all of the same (generated) type

print(type(linode)) # openapi.schemas.Linode

type(linode) == type(linodes.data[0]) # True

# call an operation with a request body

new_linode = api.call_createLinodeInstance(data={"region":"us-east","type":"g6-standard-2"})

# the returned models is still of the correct type

type(new_linode) == type(linode) # True

http基本身份验证和http摘要身份验证的工作方式如下:# authenticate using a securityScheme defined in the spec's components.securtiySchemes

# Tuple with (username, password) as second argument

api.authenticate('basicAuth', ('username', 'password'))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值