Crunch.io客户端库
项目描述
A Python client library for Crunch.io.
使用pycrunch
要在项目中使用pycrunch,请运行
$ python setup.py develop
这将使此目录中的代码对其他项目可用。
入门
通过以下方式启动简单的站点会话:
>>> import pycrunch >>> site = pycrunch.connect(api_key="DFIJFIJWIEJIJFKSJLKKDJKFJSLLSLSL", site_url="https://your-domain.crunch.io/api/")
或者,如果您没有API密钥
>>> site = pycrunch.connect("me@mycompany.com", "yourpassword", "https://your-domain.crunch.io/api/")
然后,您可以创建一个API密钥
>>> apk = site.apikeys.create({"body": {"name": "API Key"}})
>>> apk.refresh()
>>> site_via_api_key = pycrunch.connect(api_key=apk.body["key"], site_url="https://your-domain.crunch.io/api/")
或者,如果您有Crunch访问令牌
>>> import pycrunch
>>> site = pycrunch.connect_with_token("DFIJFIJWIEJIJFKSJLKKDJKFJSLLSLSL", "https://your-domain.crunch.io/api/")
然后,您可以浏览网站。使用 print 来美化打印 JSON 负载数据
>>> print(site)
pycrunch.shoji.Catalog(**{
"element": "shoji:catalog",
"self": "https://your-domain.crunch.io/api/",
"description": "The API root.",
"catalogs": {
"datasets": "https://your-domain.crunch.io/api/datasets/",
...
},
"urls": {
"logout_url": "https://your-domain.crunch.io/api/logout/",
...
},
"views": {
"migration": "https://your-domain.crunch.io/api/migration/"
}
})
负载的目录、视图、片段和 URL 集合中的 URI 可以自动访问
>>> print(site.datasets)
pycrunch.shoji.Catalog(**{
"self": "https://your-domain.crunch.io/api/datasets/",
"element": "shoji:catalog",
"index": {
"https://your-domain.crunch.io/api/datasets/dbf9fca7b727/": {
"owner_display_name": "me@mycompany.com",
"description": "",
"id": "dbf9fca7b727",
"owner_id": "https://your-domain.crunch.io/api/users/253b68/",
"archived": false,
"name": "Hog futures tracking (May 2014)"
},
},
...
})
每个识别的 JSON 负载还自动提供对每个 JSON 对象成员的点属性访问
>>> print(site.datasets.index.values()[0])
pycrunch.shoji.Tuple(**{
"owner_display_name": "me@mycompany.com",
"description": "",
"id": "dbf9fca7b727",
"owner_id": "https://your-domain.crunch.io/api/users/253b68/",
"archived": false,
"name": "Hog futures tracking (May 2014)"
})
响应还可以具有附加的帮助程序,例如目录索引中每个元组的 entity 属性,该属性遵循到实体资源的链接
>>> print(site.datasets.index.values()[0].entity_url) "https://your-domain.crunch.io/api/datasets/dbf9fca7b727/">>> print(site.datasets.index.values()[0].entity) pycrunch.shoji.Entity(**{ "self": "https://your-domain.crunch.io/api/datasets/dbf9fca7b727/", "element": "shoji:entity", "description": "Detail for a given dataset", "body": { "archived": false, "user_id": "253b68", "name": "Hog futures tracking (May 2014)" "weight": "https://your-domain.crunch.io/api/datasets/dbf9fca7b727/variables/36f5404/", "creation_time": "2014-03-06T18:23:26.780752+00:00", "description": "" }, "catalogs": { "batches": "https://your-domain.crunch.io/api/datasets/dbf9fca7b727/batches/", "joins": "https://your-domain.crunch.io/api/datasets/dbf9fca7b727/joins/", "variables": "https://your-domain.crunch.io/api/datasets/dbf9fca7b727/variables/", "filters": "https://your-domain.crunch.io/api/datasets/dbf9fca7b727/filters/", ... }, "views": { "cube": "https://your-domain.crunch.io/api/datasets/dbf9fca7b727/cube/", ... }, "urls": { "revision_url": "https://your-domain.crunch.io/api/datasets/dbf9fca7b727/revision/", ... }, "fragments": { "table": "https://your-domain.crunch.io/api/datasets/dbf9fca7b727/table/" } })
通常您通过其 create 方法将新资源添加到目录中
>>> ds = site.datasets.create({"body": {
'name': "My first dataset"
}}, refresh=True)
>>> gender = ds.variables.create({"body": {
'name': 'Gender',
'alias': 'gender',
'type': 'categorical',
'categories': [
{'id': -1, 'name': 'No Data', 'numeric_value': None, 'missing': True},
{'id': 1, 'name': 'M', 'numeric_value': None, 'missing': False},
{'id': 2, 'name': 'F', 'numeric_value': None, 'missing': False}
],
'values': [1, 2, {"?": -1}, 2]
}}, refresh=True)
>>> print(ds.table.data)
pycrunch.elements.JSONObject(**{
"e7f361628": [
1,
2,
{"?": -1},
2
]
})
要访问数据集中数据的 Pandas Dataframe
>>> from pycrunch import pandaslib as crunchpandas >>> df = crunchpandas.dataframe_from_dataset(site,'baadf00d000339d9faadg00beab11e') >>> print(df) < Draws a dataframe table >
项目详情
下载文件
下载您平台上的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源分布
pycrunch-0.5.8.tar.gz (48.4 kB 查看散列)
构建分布
pycrunch-0.5.8-py2.py3-none-any.whl (43.5 kB 查看散列)
关闭
pycrunch-0.5.8.tar.gz 的散列
| 算法 | 散列摘要 | |
|---|---|---|
| SHA256 | bb95d4e504029afaa4c150fec76dfd04989a28e70c2c91431609a5579b24f707 |
|
| MD5 | 743c3e276c6365a9ddc5caf0929fc26c |
|
| BLAKE2b-256 | d1da2c4afa371ead6d65bce7ab0c07c9dfa14c1252a8f14d037019a8b5b12751 |
关闭
pycrunch-0.5.8-py2.py3-none-any.whl 的散列
| 算法 | 散列摘要 | |
|---|---|---|
| SHA256 | 324f7d99f60144c02f32f9004c5bea6879ff614b793224d223e580965348663a |
|
| MD5 | 8113f4a18cf2b95a21a5cdbab454c0a6 |
|
| BLAKE2b-256 | 6e5b85f205da63904bbe836282c9687431f357733d17fd1b7ecc773f4d491fbe |