pycrunch
A Python client library for Crunch.io.
Using pycrunch
To use pycrunch in your project, run:
$ python setup.py develop
This will make the code in this directory available to other projects.
Getting started
Start a simple site session via:
>>> import pycrunch >>> site = pycrunch.connect(api_key="DFIJFIJWIEJIJFKSJLKKDJKFJSLLSLSL", site_url="https://your-domain.crunch.io/api/")
Or, if you don’t have an API Key:
>>> site = pycrunch.connect("me@mycompany.com", "yourpassword", "https://your-domain.crunch.io/api/")
Then, you can create an API Key:
>>> 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/")
Or, if you have a crunch access token:
>>> import pycrunch
>>> site = pycrunch.connect_with_token("DFIJFIJWIEJIJFKSJLKKDJKFJSLLSLSL", "https://your-domain.crunch.io/api/")
Then, you can browse the site. Use print to pretty-indent JSON payloads:
>>> 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/"
}
})
URI’s in payloads’ catalogs, views, fragments, and urls collections are followable automatically:
>>> 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)"
},
},
...
})
Each recognized JSON payload also automatically gives dotted-attribute access to the members of each JSON object:
>>> 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)"
})
Responses may also possess additional helpers, like the entity property of each Tuple in a catalog’s index, which follows the link to the Entity resource:
>>> 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/" } })
### Creating a New Dataset
You typically add new resources to a Catalog via its create method:
>>> ds = site.datasets.create({"body": {
"name": "My first dataset",
"project": "https://your-domain.crunch.io/api/projects/dbf9foo7b727/"
}})
>>> ds.refresh()
>>> 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]
}})
>>> print(ds.table.metadata)
pycrunch.elements.JSONObject(**{
"dbebef213d3d413398f0c4075acb05a7": {
"alias": "gender",
"name": "Gender",
"type": "categorical",
"description": "",
"notes": "",
"derived": false,
"categories": [
{
"missing": true,
"numeric_value": null,
"id": -1,
"name": "No Data"
},
{
"missing": false,
"numeric_value": null,
"id": 1,
"name": "M"
},
{
"missing": false,
"numeric_value": null,
"id": 2,
"name": "F"
}
]
}
})
To access a Pandas Dataframe of the data in your dataset:
>>> from pycrunch import pandaslib as crunchpandas >>> df = crunchpandas.dataframe_from_dataset(site,'baadf00d000339d9faadg00beab11e') >>> print(df) < Draws a dataframe table >
Metadata
Release files for pycrunch 0.5.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pycrunch-0.5.9.tar.gz | 50.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pycrunch-0.5.9-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 94.6 kB
Release files / pycrunch-0.5.9.tar.gz
| Download URL | pycrunch-0.5.9.tar.gz |
|---|---|
| Size | 50.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fb652294f1480a55cc72f4f4812d3906c5819ec500836aad643828bdecb3819a
|
|
BLAKE2b-256 checksum How to use checksums |
fd7710f01fc0ba305daf08809a2129d13cdfd01d4326111695d3dcb4e738565f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.28.2 requests-toolbelt/0.10.1 urllib3/1.26.14 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.15
|
Release files / pycrunch-0.5.9-py2.py3-none-any.whl
| Download URL | pycrunch-0.5.9-py2.py3-none-any.whl |
|---|---|
| Size | 44.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
1dd14146dc79421feb7a4a7831494f15750025a5b35dad2b9436b99794880e70
|
|
BLAKE2b-256 checksum How to use checksums |
3351bda202d23b6f9fb177fcceeac65b76a319b5aba11883d2fe0015c836fbae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.28.2 requests-toolbelt/0.10.1 urllib3/1.26.14 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.15
|
Security for pycrunch 0.5.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.