Module for working with Unfolded Studio's Data SDK
Project description
unfolded.data-sdk
Python package for interfacing with Unfolded's Data SDK.
Installation
Install via pip:
pip install -U unfolded.data-sdk
Authentication
Before using the Data SDK, you must authenticate. Authentication with a refresh token only needs to be done once, and can be done either through the CLI or Python module. First go to studio.unfolded.ai/tokens.html to sign in. Then copy the Refresh Token for use in the next step.
CLI
To authenticate via the CLI, use the store-refresh-token
method:
> uf-data-sdk store-refresh-token
The CLI will then prompt for your refresh token, and print a message when it has successfully stored it.
Python module
To authenticate via the Python module, pass the refresh token to the DataSDK
class. This only needs to happen once. For future uses of the DataSDK
class, do not pass a refresh_token
argument.
from unfolded.data_sdk import DataSDK
DataSDK(refresh_token='v1.ABC...')
Usage
CLI
The CLI is available through uf-data-sdk
on the command line. Running that
without any other arguments gives you a list of available commands:
> uf-data-sdk
Usage: uf-data-sdk [OPTIONS] COMMAND [ARGS]...
Options:
--help Show this message and exit.
Commands:
delete-dataset Delete dataset from Unfolded Studio Warning: This...
download-dataset Download data for existing dataset to disk
list-datasets List datasets for a given user
store-refresh-token Store refresh token to enable seamless future...
update-dataset Update data for existing Unfolded Studio dataset
upload-file Upload new dataset to Unfolded Studio
Then to see how to use a command, pass --help
to a subcommand:
> uf-data-sdk download-dataset --help
Usage: uf-data-sdk download-dataset [OPTIONS]
Download data for existing dataset to disk
Options:
--dataset-id TEXT Dataset id. [required]
-o, --output-file PATH Output file for dataset. [required]
--help Show this message and exit.
Python Package
The Python package can be imported via unfolded.data_sdk
:
from unfolded.data_sdk import DataSDK, MediaType
data_sdk = DataSDK()
List Datasets
List datasets for given user
datasets = data_sdk.list_datasets()
Get Dataset by ID
Get dataset given its id
dataset = datasets[0]
data_sdk.get_dataset_by_id(dataset)
Download dataset data
Download data for dataset given its id
dataset = datasets[0]
data_sdk.download_dataset(dataset, output_file='output.csv')
Upload new dataset
Upload new dataset to Unfolded Studio
data_sdk.upload_file(
file='new_file.csv',
name='Dataset name',
media_type=MediaType.CSV,
description='Dataset description')
Update existing dataset
Update data for existing Unfolded Studio dataset
dataset = datasets[0]
data_sdk.update_dataset(
file='new_file.csv',
dataset=dataset,
media_type=MediaType.CSV)
Delete dataset
Delete dataset from Unfolded Studio
Warning: This operation cannot be undone. If you delete a dataset currently used in one or more maps, the dataset will be removed from those maps, possibly causing them to render incorrectly.
dataset = datasets[0]
data_sdk.delete_dataset(dataset)
DataFrame support
The Python package makes it simple to upload pandas DataFrames
and geopandas
GeoDataFrames
to Unfolded Studio. Pass either a DataFrame
or a
GeoDataFrame
to upload_dataframe
:
import pandas as pd
df = pd.DataFrame({'column1': [1, 2, 3, 4]})
data_sdk.upload_dataframe(df, 'Dataset Name')
import geopandas as gpd
gdf = gpd.read_file('path/to/data.geojson')
data_sdk.upload_dataframe(gdf, 'Dataset Name')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file unfolded.data-sdk-0.2.0.tar.gz
.
File metadata
- Download URL: unfolded.data-sdk-0.2.0.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/46.4.0.post20200518 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8772a36a7e74590c334dfd7acc8c055842d2eb80e6d3e41c7e0a0a069602038d |
|
MD5 | e5c46851f0bc60c57ee5bcfc972b0366 |
|
BLAKE2b-256 | 99dacf31d6d0e448d574099ad177b97b0e76157640059fe0a24b1dd643153429 |