用于访问启用了swagger的api的库
bravado的Python项目详细描述
虚张声势
关于
虚张声势是由digium/swagger-py发出的尖叫声 用于OpenAPI Specification version 2.0(以前 被称为招摇过市)。
来自openapi规范项目:
The goal of The OpenAPI Specification is to define a standard, language-agnostic interface to REST APIs which allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection.
客户端库可以根据openapi规范自动生成, 然而Bravado的目标是完全替代代码生成 (swagger-codegen)。
示例用法
frombravado.clientimportSwaggerClientclient=SwaggerClient.from_url('http://petstore.swagger.io/v2/swagger.json')pet=client.pet.getPetById(petId=42).response().result
基本认证示例
frombravado.requests_clientimportRequestsClientfrombravado.clientimportSwaggerClienthttp_client=RequestsClient()http_client.set_basic_auth('api.yourhost.com','username','password')client=SwaggerClient.from_url('http://petstore.swagger.io/v2/swagger.json',http_client=http_client,)pet=client.pet.getPetById(petId=42).response().result
头部认证示例
frombravado.requests_clientimportRequestsClientfrombravado.clientimportSwaggerClienthttp_client=RequestsClient()http_client.set_api_key('api.yourhost.com','token',param_name='api_key',param_in='header')client=SwaggerClient.from_url('http://petstore.swagger.io/v2/swagger.json',http_client=http_client,)pet=client.pet.getPetById(petId=42).response().result
Fido客户端(异步Http客户端)的示例
# Install bravado with fido extra (``pip install bravado[fido]``)frombravado.fido_clientimportFidoClientfrombravado.clientimportSwaggerClienthttp_client=FidoClient()client=SwaggerClient.from_url('http://petstore.swagger.io/v2/swagger.json',http_client=http_client,)pet=client.pet.getPetById(petId=42).response().result
文件
安装
# To install bravado with Synchronous Http Client only. $ pip install bravado # To install bravado with Synchronous and Asynchronous Http Client (RequestsClient and FidoClient). $ pip install bravado[fido]
开发
使用Sphinx记录代码。
virtualenv。是 建议保持依赖项和库的隔离。
设置
# Run tests tox # Install git pre-commit hooks tox -e pre-commit install
贡献
- 叉它(http://github.com/Yelp/bravado/fork)
- 创建功能分支(git checkout -bmy-new-feature)
- 添加您的修改
- 在CHANGELOG-MASTER.rst
- 提交更改(git commit -m "Add some feature")
- 推到分支(git push origin my-new-feature)
- 创建新的拉取请求