Skip to main content

Graviti Python SDK

Project description

Graviti Python SDK

Pre-commit Documentation Status GitHub PyPI PyPI - Python Version Downloads

Graviti Python SDK is a python library to access Graviti 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:

pip3 install graviti

Or from source:

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

Usage

Before using Graviti SDK, please finish the following registration steps:

Get a Dataset

Workspace initialization:

from graviti import Workspace
ws = Workspace(f"{YOUR_ACCESSKEY}")

List datasets on the workspace:

>>> ws.datasets.list()
LazyPagingList [
  Dataset("graviti-example/Graviti-dataset-demo")
]

Get one dataset:

>>> 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,
  (config): 'AmazonS3-us-west-1'
)

Switch Between Different Versions

View the current version of the dataset:

>>> 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:

>>> dataset.commits.list()
LazyPagingList [
  Commit("47293b32f28c4008bc0f25b847b97d6f")
]

List all branches:

>>> dataset.branches.list()
LazyPagingList [
  Branch("main"),
  Branch("dev")
]

List all tags:

>>> dataset.tags.list()
LazyPagingList [
  Tag("v1.0")
]

Checkout commit/branch/tag:

>>> 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,
)
>>> 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,
)
>>> 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:

>>> list(dataset.keys())
['train']

Get a sheet:

>>> 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:

>>> 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:

>>> 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:

>>> df.loc[0]
filename  a.jpg
box2ds    DataFrame(1, 6)
>>> df["box2ds"]
0  DataFrame(1, 6)
1  DataFrame(1, 6)
2  DataFrame(1, 6)
>>> df.loc[0]["box2ds"]
   xmin  ymin  xmax  ymax  category  attribute
                                     difficult  occluded
0  1.0   1.0   4.0   5.0   boat      False      False
>>> df["box2ds"][0]
   xmin  ymin  xmax  ymax  category  attribute
                                     difficult  occluded
0  1.0   1.0   4.0   5.0   boat      False      False

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

graviti-0.7.3.tar.gz (84.8 kB view details)

Uploaded Source

Built Distribution

graviti-0.7.3-py3-none-any.whl (122.7 kB view details)

Uploaded Python 3

File details

Details for the file graviti-0.7.3.tar.gz.

File metadata

  • Download URL: graviti-0.7.3.tar.gz
  • Upload date:
  • Size: 84.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.13

File hashes

Hashes for graviti-0.7.3.tar.gz
Algorithm Hash digest
SHA256 6a2160e2e41ef73330a7cc0639ee87726a0f7698d74b9e59f1d8688fb0d2ec59
MD5 43072696105abb80582eaa62829f82ce
BLAKE2b-256 b3a836a57e1284894c9aded50cf878cccb4c8d80795ed59ea531d6959b9e00f8

See more details on using hashes here.

File details

Details for the file graviti-0.7.3-py3-none-any.whl.

File metadata

  • Download URL: graviti-0.7.3-py3-none-any.whl
  • Upload date:
  • Size: 122.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.13

File hashes

Hashes for graviti-0.7.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e67f63ff0fe99c4cea738bb794850358fe1598267b61dd0ee00358bd62c321bc
MD5 b5ef0ebe14c995f908d59ef6833d2a91
BLAKE2b-256 b3bdc5546d1a378e12b1be1b0b0346e09f443657da16f4a87a22ab2c2b723213

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page