# Graviti Python SDK
[![Pre-commit](https://github.com/Graviti-AI/graviti-python-sdk/actions/workflows/pre-commit.yaml/badge.svg)](https://github.com/Graviti-AI/graviti-python-sdk/actions/workflows/pre-commit.yaml)
[![Documentation Status](https://readthedocs.org/projects/graviti-python-sdk/badge/?version=latest)](https://graviti-python-sdk.readthedocs.io/en/latest/?badge=latest)
[![GitHub](https://img.shields.io/github/license/Graviti-AI/graviti-python-sdk)](https://github.com/Graviti-AI/graviti-python-sdk/blob/main/LICENSE)
[![PyPI](https://img.shields.io/pypi/v/graviti)](https://pypi.org/project/graviti/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/graviti)](https://pypi.org/project/graviti/)
[![Downloads](https://pepy.tech/badge/graviti/month)](https://pepy.tech/project/graviti)
Graviti Python SDK is a python library to access [Graviti](https://www.graviti.com) workspace and
manage your datasets. It provides a pythonic way to access your datasets by Graviti OpenAPI.
---
**NOTE: This project is still on pre-alpha stage, may have breaking changes in the future.**
---
## Installation
Graviti can be installed from PyPI:
```console
pip3 install graviti
```
Or from source:
```console
git clone https://github.com/Graviti-AI/graviti-python-sdk.git
cd graviti-python-sdk
pip install -e .
```
## Documentation
More information can be found on the [documentation site](https://graviti-python-sdk.readthedocs.io)
## Usage
Before using Graviti SDK, please finish the following registration steps:
- Please visit [Graviti](https://www.graviti.com) to sign up.
- Please visit [Graviti Developer Tools](https://gas.graviti.com/tensorbay/developer) to get an **AccessKey**.
### Get a Dataset
Workspace initialization:
```python
from graviti import Workspace
ws = Workspace(f"{YOUR_ACCESSKEY}")
```
List datasets on the workspace:
```python
>>> ws.datasets.list()
LazyPagingList [
Dataset("graviti-example/Graviti-dataset-demo")
]
```
Get one dataset:
```python
>>> dataset = ws.datasets.get("Graviti-dataset-demo")
>>> dataset
Dataset("graviti-example/Graviti-dataset-demo")(
(alias): '',
(default_branch): 'main',
(created_at): 2022-07-20 04:22:35+00:00,
(updated_at): 2022-07-20 04:23:45+00:00,
(is_public): False,
(storage_config): 'AmazonS3-us-west-1'
)
```
### Switch Between Different Versions
View the current version of the dataset:
```python
>>> dataset.HEAD
Branch("main")(
(commit_id): '47293b32f28c4008bc0f25b847b97d6f',
(parent): None,
(title): 'Commit-1',
(committer): 'graviti-example',
(committed_at): 2022-07-20 04:22:35+00:00,
)
```
List history commits:
```python
>>> dataset.commits.list()
LazyPagingList [
Commit("47293b32f28c4008bc0f25b847b97d6f")
]
```
List all branches:
```python
>>> dataset.branches.list()
LazyPagingList [
Branch("main"),
Branch("dev")
]
```
List all tags:
```python
>>> dataset.tags.list()
LazyPagingList [
Tag("v1.0")
]
```
Checkout commit/branch/tag:
```python
>>> dataset.checkout("47293b32f28c4008bc0f25b847b97d6f") # commit id
>>> dataset.HEAD
Commit("47293b32f28c4008bc0f25b847b97d6f")(
(parent): None,
(title): 'Commit-1',
(committer): 'graviti-example',
(committed_at): 2022-07-20 04:22:35+00:00,
)
```
```python
>>> dataset.checkout("dev") # branch name
>>> dataset.HEAD
Branch("dev")(
(commit_id): '47293b32f28c4008bc0f25b847b97d6f',
(parent): None,
(title): 'Commit-1',
(committer): 'graviti-example',
(committed_at): 2022-07-20 04:22:35+00:00,
)
```
```python
>>> dataset.checkout("v1.0") # tag name
>>> dataset.HEAD
Commit("47293b32f28c4008bc0f25b847b97d6f")(
(parent): None,
(title): 'Commit-1',
(committer): 'graviti-example',
(committed_at): 2022-07-20 04:22:35+00:00,
)
```
### Get a Sheet
List all sheets:
```python
>>> list(dataset.keys())
['train']
```
Get a sheet:
```python
>>> dataset["train"]
filename box2ds
0 a.jpg DataFrame(1, 6)
1 b.jpg DataFrame(1, 6)
2 c.jpg DataFrame(1, 6)
```
### Get the Data
Get the DataFrame:
```python
>>> df = dataset["train"]
>>> df
filename box2ds
0 a.jpg DataFrame(1, 6)
1 b.jpg DataFrame(1, 6)
2 c.jpg DataFrame(1, 6)
```
View the schema of the sheet:
```python
>>> df.schema
record(
fields={
'filename': string(),
'box2ds': array(
items=label.Box2D(
coords=float32(),
categories=['boat', 'car'],
attributes={
'difficult': boolean(),
'occluded': boolean(),
},
),
),
},
)
```
Get the data by rows or columns:
```python
>>> df.loc[0]
filename a.jpg
box2ds DataFrame(1, 6)
```
```python
>>> df["box2ds"]
0 DataFrame(1, 6)
1 DataFrame(1, 6)
2 DataFrame(1, 6)
```
```python
>>> df.loc[0]["box2ds"]
xmin ymin xmax ymax category attribute
difficult occluded
0 1.0 1.0 4.0 5.0 boat False False
```
```python
>>> df["box2ds"][0]
xmin ymin xmax ymax category attribute
difficult occluded
0 1.0 1.0 4.0 5.0 boat False False
```
Raw data
{
"_id": null,
"home_page": "https://github.com/Graviti-AI/graviti-python-sdk",
"name": "graviti",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "graviti,dataset,DataFrame",
"author": "Graviti",
"author_email": "pypi@graviti.com",
"download_url": "https://files.pythonhosted.org/packages/50/31/fa031d9cb2f539827b458da752b04faa17654d1ad1934868774d6a623971/graviti-0.13.0.tar.gz",
"platform": null,
"description": "# Graviti Python SDK\n\n[![Pre-commit](https://github.com/Graviti-AI/graviti-python-sdk/actions/workflows/pre-commit.yaml/badge.svg)](https://github.com/Graviti-AI/graviti-python-sdk/actions/workflows/pre-commit.yaml)\n[![Documentation Status](https://readthedocs.org/projects/graviti-python-sdk/badge/?version=latest)](https://graviti-python-sdk.readthedocs.io/en/latest/?badge=latest)\n[![GitHub](https://img.shields.io/github/license/Graviti-AI/graviti-python-sdk)](https://github.com/Graviti-AI/graviti-python-sdk/blob/main/LICENSE)\n[![PyPI](https://img.shields.io/pypi/v/graviti)](https://pypi.org/project/graviti/)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/graviti)](https://pypi.org/project/graviti/)\n[![Downloads](https://pepy.tech/badge/graviti/month)](https://pepy.tech/project/graviti)\n\nGraviti Python SDK is a python library to access [Graviti](https://www.graviti.com) workspace and\nmanage your datasets. It provides a pythonic way to access your datasets by Graviti OpenAPI.\n\n---\n\n**NOTE: This project is still on pre-alpha stage, may have breaking changes in the future.**\n\n---\n\n## Installation\n\nGraviti can be installed from PyPI:\n\n```console\npip3 install graviti\n```\n\nOr from source:\n\n```console\ngit clone https://github.com/Graviti-AI/graviti-python-sdk.git\ncd graviti-python-sdk\npip install -e .\n```\n\n## Documentation\n\nMore information can be found on the [documentation site](https://graviti-python-sdk.readthedocs.io)\n\n## Usage\n\nBefore using Graviti SDK, please finish the following registration steps:\n\n- Please visit [Graviti](https://www.graviti.com) to sign up.\n- Please visit [Graviti Developer Tools](https://gas.graviti.com/tensorbay/developer) to get an **AccessKey**.\n\n### Get a Dataset\n\nWorkspace initialization:\n\n```python\nfrom graviti import Workspace\nws = Workspace(f\"{YOUR_ACCESSKEY}\")\n```\n\nList datasets on the workspace:\n\n```python\n>>> ws.datasets.list()\nLazyPagingList [\n Dataset(\"graviti-example/Graviti-dataset-demo\")\n]\n```\n\nGet one dataset:\n\n```python\n>>> dataset = ws.datasets.get(\"Graviti-dataset-demo\")\n>>> dataset\nDataset(\"graviti-example/Graviti-dataset-demo\")(\n (alias): '',\n (default_branch): 'main',\n (created_at): 2022-07-20 04:22:35+00:00,\n (updated_at): 2022-07-20 04:23:45+00:00,\n (is_public): False,\n (storage_config): 'AmazonS3-us-west-1'\n)\n```\n\n### Switch Between Different Versions\n\nView the current version of the dataset:\n\n```python\n>>> dataset.HEAD\nBranch(\"main\")(\n (commit_id): '47293b32f28c4008bc0f25b847b97d6f',\n (parent): None,\n (title): 'Commit-1',\n (committer): 'graviti-example',\n (committed_at): 2022-07-20 04:22:35+00:00,\n)\n```\n\nList history commits:\n\n```python\n>>> dataset.commits.list()\nLazyPagingList [\n Commit(\"47293b32f28c4008bc0f25b847b97d6f\")\n]\n```\n\nList all branches:\n\n```python\n>>> dataset.branches.list()\nLazyPagingList [\n Branch(\"main\"),\n Branch(\"dev\")\n]\n```\n\nList all tags:\n\n```python\n>>> dataset.tags.list()\nLazyPagingList [\n Tag(\"v1.0\")\n]\n```\n\nCheckout commit/branch/tag:\n\n```python\n>>> dataset.checkout(\"47293b32f28c4008bc0f25b847b97d6f\") # commit id\n>>> dataset.HEAD\nCommit(\"47293b32f28c4008bc0f25b847b97d6f\")(\n (parent): None,\n (title): 'Commit-1',\n (committer): 'graviti-example',\n (committed_at): 2022-07-20 04:22:35+00:00,\n)\n```\n\n```python\n>>> dataset.checkout(\"dev\") # branch name\n>>> dataset.HEAD\nBranch(\"dev\")(\n (commit_id): '47293b32f28c4008bc0f25b847b97d6f',\n (parent): None,\n (title): 'Commit-1',\n (committer): 'graviti-example',\n (committed_at): 2022-07-20 04:22:35+00:00,\n)\n```\n\n```python\n>>> dataset.checkout(\"v1.0\") # tag name\n>>> dataset.HEAD\nCommit(\"47293b32f28c4008bc0f25b847b97d6f\")(\n (parent): None,\n (title): 'Commit-1',\n (committer): 'graviti-example',\n (committed_at): 2022-07-20 04:22:35+00:00,\n)\n```\n\n### Get a Sheet\n\nList all sheets:\n\n```python\n>>> list(dataset.keys())\n['train']\n```\n\nGet a sheet:\n\n```python\n>>> dataset[\"train\"]\n filename box2ds\n0 a.jpg DataFrame(1, 6)\n1 b.jpg DataFrame(1, 6)\n2 c.jpg DataFrame(1, 6)\n```\n\n### Get the Data\n\nGet the DataFrame:\n\n```python\n>>> df = dataset[\"train\"]\n>>> df\n filename box2ds\n0 a.jpg DataFrame(1, 6)\n1 b.jpg DataFrame(1, 6)\n2 c.jpg DataFrame(1, 6)\n```\n\nView the schema of the sheet:\n\n```python\n>>> df.schema\nrecord(\n fields={\n 'filename': string(),\n 'box2ds': array(\n items=label.Box2D(\n coords=float32(),\n categories=['boat', 'car'],\n attributes={\n 'difficult': boolean(),\n 'occluded': boolean(),\n },\n ),\n ),\n },\n)\n```\n\nGet the data by rows or columns:\n\n```python\n>>> df.loc[0]\nfilename a.jpg\nbox2ds DataFrame(1, 6)\n```\n\n```python\n>>> df[\"box2ds\"]\n0 DataFrame(1, 6)\n1 DataFrame(1, 6)\n2 DataFrame(1, 6)\n```\n\n```python\n>>> df.loc[0][\"box2ds\"]\n xmin ymin xmax ymax category attribute\n difficult occluded\n0 1.0 1.0 4.0 5.0 boat False False\n```\n\n```python\n>>> df[\"box2ds\"][0]\n xmin ymin xmax ymax category attribute\n difficult occluded\n0 1.0 1.0 4.0 5.0 boat False False\n```\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Graviti Python SDK",
"version": "0.13.0",
"split_keywords": [
"graviti",
"dataset",
"dataframe"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "7ba38276e744a48c4e03f36e18b8a0b5",
"sha256": "73c79e20aeaadea701caea2cf57fbc77573a9a308376084b7bfa2fa30bd87a92"
},
"downloads": -1,
"filename": "graviti-0.13.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7ba38276e744a48c4e03f36e18b8a0b5",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 155640,
"upload_time": "2022-12-02T10:57:48",
"upload_time_iso_8601": "2022-12-02T10:57:48.991371Z",
"url": "https://files.pythonhosted.org/packages/63/c5/4e2170b3db0ed005a98bf4b6076238056e697aae8e92ab1ed34c1977ea51/graviti-0.13.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "cae42c671123087034b9259ae182c66c",
"sha256": "0cd32101e4fdf303e6b2ef2f39acf42e45ae2516d1ee1878d9357a1faf9d5434"
},
"downloads": -1,
"filename": "graviti-0.13.0.tar.gz",
"has_sig": false,
"md5_digest": "cae42c671123087034b9259ae182c66c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 108311,
"upload_time": "2022-12-02T10:57:52",
"upload_time_iso_8601": "2022-12-02T10:57:52.786159Z",
"url": "https://files.pythonhosted.org/packages/50/31/fa031d9cb2f539827b458da752b04faa17654d1ad1934868774d6a623971/graviti-0.13.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-12-02 10:57:52",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "Graviti-AI",
"github_project": "graviti-python-sdk",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "urllib3",
"specs": [
[
">=",
"1.15"
]
]
},
{
"name": "requests",
"specs": [
[
">=",
"2.4.2"
]
]
},
{
"name": "requests_toolbelt",
"specs": [
[
">=",
"0.3.0"
]
]
},
{
"name": "pyyaml",
"specs": [
[
">=",
"5.1"
]
]
},
{
"name": "pyarrow",
"specs": [
[
">=",
"3.0.0"
]
]
},
{
"name": "tqdm",
"specs": [
[
">=",
"4.27.0"
]
]
},
{
"name": "typing_extensions",
"specs": [
[
">=",
"3.7.2"
]
]
}
],
"lcname": "graviti"
}