一个小库,提供对超导graphql api的编程访问。
cooper-pair的Python项目详细描述
配对
cooper_pair
是一个python库,提供对超导graphql api的编程访问。
它支持有限数量的通用用例。(见下文。)
cooper_pair
是not打算用作graphql的通用集成库。
最有用的graphql查询是not在cooper_pair
api中受支持。
为什么要限制用例?
graphql是一种可组合的查询语言。允许的查询空间很大,而且 开发人员有权为给定的作业选择正确的查询。这种夫妻关系的发展 在使用api并允许每个api更快移动的开发过程中, 独立地。
在一个硬Python库中封装一个灵活的API将完全达到这个目的。相反,把cooper_pair
看作是训练车轮。它使快速连接变得容易
并执行一些常见的函数。它还提供了一组示例
查询以了解如何使用GraphQL和同素异形API。
换句话说,cooper-pair
可以帮助您开始,但是您将能够获得更多
一旦你学会了使用graphql查询它。
安装
cd cooper-pair
pip install .
或者,
pip install git+ssh://git@github.com/superconductive/cooper.git#egg=cooper_pair&subdirectory=pair
用法
实例化api
from cooper_pair import CooperPair
pair = CooperPair(
graphql_endpoint="http://my-data-valet-url:3010/graphql",
email='my_user@some_email.com',
password='my_very_secure_password'
)
列出数据集
response = pair.list_datasets()
print( json.dumps(response, indent=2))
获取数据集
response = pair.get_dataset("RGF2YXNldPoxODl=")
print( json.dumps(response, indent=2))
列出检查点
response = pair.list_checkpoints()
print( json.dumps(response, indent=2) )
创建一个新的数据集,并根据现有的检查点对其进行评估
从数据帧:
my_df = pd.DataFrame({
"x" : [1,2,3,4,5],
"y" : [6,7,8,9,10],
})
response = pair.evaluate_checkpoint_on_pandas_df(
checkpoint_id="Q2hlY2twb2ludDox",
pandas_df=my_df,
filename="my_dataframe_name"
)
evaluation_id = response['addEvaluation']['evaluation']['id']
dataset_id = response['addEvaluation']['evaluation']['dataset']['id']
从文件:
with open('my_file.csv', 'rb') as fd:
dataset = pair.evaluate_checkpoint_on_file(
checkpoint_id="Q2hlY2twb2ludDox",
fd=fd,
)
evaluation_id = response['addEvaluation']['evaluation']['id']
dataset_id = response['addEvaluation']['evaluation']['dataset']['id']
注意:评估是异步的。当同素异形体第一次返回响应时,
它将有status="created"
。当一个工人捡起它时,它将变为pending
,
然后根据评估结果来success
或failed
。
您可以按如下方式查询状态:
response = pair.query("""
query evaluationQuery($id: ID!) {
evaluation(id: $id) {
id,
status
}
}
""",
variables={
'id' : evaluation_id
})
print(response)
从json创建新的检查点
import json
with open('checkpoint_definition.json', 'rb') as fd:
checkpoint_config = json.load(fd)
pair.add_checkpoint_from_expectations_config(
checkpoint_config, "Checkpoint Name")