q-ctrl python api客户端

qctrl-api-client的Python项目详细描述


q-ctrl python api客户端

CircleCI

qctrlpythonapi客户端为q ctrl的 restful http api。

目录

安装

pip install qctrl-api-client

用法

设置

fromqctrlapiclientimportApiapi=Api("YOUR_API_KEY")

检索数据

Api类附带一些函数,这些函数将帮助您查找数据和 过滤它。最常用的方法是find()

查找

find(type,options=None)

find是所有数据检索功能的多功能工作台。"type" 可以是"all""first"

options用于将所有选项传递给各种类型的find(),并且 以下可能的键(每个键都是可选的):

options={# Find resources based on a list of filter conditions"filter":{"field_1":"value_1","field_2":"value_2",},# Improve performance by including related resources at the same time"include":["related_resource_1","related_resource_2",],# Sort the results by a list of fields# By default, results are sorted in ascending order.# To sort in descending order, prefix fields with a minus (-)."sort":["field_1","-field_2"]

查找(“第一个”)

find("first", options={})将返回一个结果。不管怎样你都会用这个 只有一个结果。

使用find('first')的示例
# Find the first systemsystem=api.systems.find("first")# Find the first control with a `type` equal to "shift" and# include its related system and pulsecontrol=api.controls.find("first",options={"filter":{"type":"shift",},"include":["systems","pulses",],})

查找(“全部”)

find("all", options={})返回可能包含多个结果的字典。

使用find('all')
的示例
# Find all systemssystems=api.systems.find("all")# Find all systems and include their related controlssystems_including_controls=api.systems.find("all",options={"include":["controls",],})

魔法查找类型

这些神奇的功能可以作为一个快捷方式,通过 字段。只需将字段的名称(以snake_case格式)添加到 这些函数提供该字段的条件作为第一个选项。

find_all_by()函数将以类似find("all")的格式返回结果, 而find_by()返回的格式与find("first")相同。

通过
查找所有
find_all_by_<field_name>(value,filter=None,include=None)
使用“全部查找”的示例
# Find all systems with an `id` equal to 7 (there will only be one)systems=api.systems.find_all_by_id(7)# Find all pulses with a `segment_count` equal to 10pulses=api.pulses.find_all_by_segment_count(10)# Find all controls with a `type` equal to "drift" and include their related systemcontrols=api.controls.find_all_by_type("drift",include=["systems"])
通过
查找
find_by_<field_name>(value,filter=None,include=None)
使用find_by的示例
# Find the system with the `id` equal to 7systems=api.systems.find_by_id(7)# Find the first pulse with a `segment_count` equal to 10pulses=api.pulses.find_by_segment_count(10)# Find the first control with a `type` equal to "drift" and# include its related systemcontrols=api.controls.find_all_by_type("drift",include=["systems"])

保存数据

准备保存的数据应传递给resourcescommit()方法。

保存数据的示例
# Save a new system with a `name` of "Master System"system=api.systems.new()system.name="Master System"system.commit()

刷新数据

每个资源都有一个refresh()方法,可用于接收任何更新的 来自api的属性。

刷新数据的示例

# Refresh a system that has been updatedprint(system.name)# "My System"system.refresh()print(system.name)# "My Updated System"

删除数据

准备删除的资源应传递给其delete()commit()。 方法。这也将删除所有相关资源。

删除数据的示例
# Delete the system with the `id` of 7 and all related resourcessystem=api.systems.find_by_id(7)system.delete()system.commit()

贡献

Contributing

测试

我们使用pytest进行单元测试。要运行单元测试,请使用以下命令:

py.test

学分

Contributors

许可证

LICENSE

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java游戏!框架伪造应用程序它实际上做什么?   java如何在JavaFx中显示表视图中的即时更改?   对象类的equals()方法的java重载   xpages介绍如何部署java。IBM Notes中的策略更改   java如何访问侦听器中的另一个视图?   java getDefaultDisplay()的替代方法是什么   java opencv匹配模板   java Android Firebase写入数据时的常量超时   在Java中,如何将包含大量空格的数字字符串转换为一系列Int变量。   带有GUI的swing Java模拟无法运行模拟   java NoSuchElementException在特定的Web端上使用无头铬和硒   java对文件进行迭代,即使文件在目录中也会出现“未找到文件”异常。你能告诉我为什么吗?谢谢   递归Java 8,匿名递归嵌套方法   java为什么我看到枚举常量的字段值会被序列化/反序列化?在哪种情况下,枚举中哪些内容没有序列化?   java在运行sonar scanner和Spotbugs规则时出错,用于单片项目?   java如何检查硬件键盘是否可用?(黑莓)   tile游戏动作侦听器循环中的java错误   sockets Java线程池与高请求场景中的新线程   java如何使用Hibernate注释在联接表上创建索引?