未来网格API客户端
fgp的Python项目详细描述
fgp api python
面向未来网格平台API的Python客户端
Work in progress! This is still under active design.
(dragons be here).
安装
pip install fgp
在命令行
该模块将安装一个命令行包装器fgp
,它允许您在命令行上执行常见的API操作。在
使用环境变量
所有参数可作为环境变量提供,前提是:
- 全部大写
- 用下划线替换短划线
- 前缀为
FGP_
以下命令都有效:
fgp --api-url http://localhost:18082 --api-app ada store --device-type meter --store-name meterPqStore get-first-last --device-name 9990000001_9880000001
以及
export FGP_API_URL=http://localhost:18082
export FGP_API_APP=ada
fgp store --device-type meter --store-name meterPqStore get-first-last --device-name 9990000001_9880000001
在Docker容器中
➜ docker run --net host --rm -it fgp-api-python --api-url http://localhost:18082 extension --device-type meter --extension-name meter_no get --device-name 9990000001_9880000001
2020-04-28 05:13:25,058 - fgp - INFO - Configured logger
2020-04-28 05:13:25.060 | DEBUG | fgp.cli.extension.commands:get:32 - Fetching extension value for extension=meter_no device=9990000001_9880000001 at timestamp=None
{
"deviceKey": {
"id": "f674e867-e987-4373-a292-96ea7657ed87"
},
"meterNo": "9990000001",
"timeKey": 1582820145000,
"timeKeyAsDate": 1582820145000,
"timestamp": 1582820145000
}
在您的应用程序中
importfgpimportdatetime# Initialise the client with your server url and application nameclient=fgp.ApiClient(url='http://localhost:8082',application='myapp',# Headers: optional, but useful if you're port forwarding to a kubernetes environment and need to use# a hostname to hit the correct ingressheaders={'Host':'api.some-environment.domain.com'})# Request data for a devicedf=client.store.get_data(device_type='meter',store_name='meterPqStore',date_from=datetime.datetime(year=2019,month=10,day=1),date_to=datetime.datetime(year=2019,month=10,day=2),fields=['voltageA','currentA'],devices=['9000000002_9000000002'])# Request extension for a deviceresult=client.extension.get_at(device_type='meter',device_name='9990000001_9880000001',extension_name='meter_no')# Request a device relationshipresult=client.relation.get_at(device_type='meter',device_name='9990000001_9880000001',relation_name='meter_transformer')# Query some reference dataclient.reference.query(reference_name='event_reference',query='eventState==NEW;nmi==9880000001',order_by="timeKey",limit=100,page=0)
计划
- 更新事件
- 项目
标签: