Python TeamDynamix API包装器
tdxapi的Python项目详细描述
tdxapi
Python TeamDynamix API包装器
注:tdxapi正在积极开发中。虽然可以安全使用,但部分API可能会发生变化。在
依赖关系
- python 3.6+
- 请求
- 属性
- python dateutil
支持的API
一般
- 帐目
- 应用
- 附件
- 属性
- 团体
资产配置管理
- 资产状态
- 资产(批量导入除外)
- 配置项类型
- 配置项
- 配置关系类型
- 产品型号
- 产品类型
- 供应商
报告
- 报告
角色
- 职能角色
- 资源池
- 安全角色
门票
- 影响
- 优先事项
- 来源
- 票证状态
- 票证任务
- 票证类型
- 门票(补丁除外)
- 紧急情况
安装
pip install tdxapi
快速启动
pip install tdxapi
创建表示到TeamDynamicx实例的连接的TdxClient对象。目前,只支持通过管理帐户登录。您可以使用use_sandbox=True
连接到沙盒:
可以直接从TdxClient实例访问非基于应用程序的api。例如,获取所有帐户的列表:
for account in tdx.accounts.all():
print(account.name)
基于应用程序的API需要使用适当的方法和应用程序id来创建应用程序对象。例如,要创建资产应用程序:
app = tdx.asset_app(123)
现在,我们可以执行与资产相关的任务,如检索资产和更新其信息:
kevins_pc = app.assets.get(123456)
kevins_pc.purchase_cost = 1000.00
app.assets.save(kevins_pc)
如果API支持添加新对象,则会有一个new()
方法来返回一个新的对象实例。使用new()
将设置对象的app_id
(如果适用),并使用基于对象类型的适用自定义属性填充attributes
:
new_asset = app.assets.new()
new_asset.name = "Kevin's Office Printer"
new_asset.serial_number = "123XYZ"
new_asset.status_id = 123 # In Use
new_asset.manufacturer_id = 456 # HP
new_asset.product_model_id = 789 # LaserJet Pro M118dw
app.assets.save(new_asset)
或者,可以在创建新对象时使用关键字参数:
new_asset = app.assets.new(
name="kevins office printer",
serial_number="123XYZ",
status_id=123,
manufacturer_id=456,
product_model_id=789
)
app.assets.save(new_asset)
自定义属性存储在一个类似于列表的容器中,并添加了一些功能,以便更轻松地使用它们。更新属性只需要属性id和值:
kevins_pc = app.assets.get(123456)
kevins_pc.attributes.update(21212, datetime.now()) # date/time attribute
kevins_pc.attributes.update(31313, "PO# 1234567") # text attribute
kevins_pc.attributes.update(41414, 11223) # single choice attribute
kevins_pc.attributes.update(51515, [13579, 24680]) # multiple choice attribute
要按属性搜索,请将custom_attributes
参数设置为包含属性id和值的元组列表:
# Find assets with a specific PO Number
assets = app.assets.search(custom_attributes=[(31313, "PO# 1234567")])
就这样吧。更好的文档和更多的API支持即将推出。在
- 项目
标签: