This article explains how to create a new data schema or data schema version using the Rhino SDK.
NOTE: If you want to learn how to use the UI to create the new data schema, see Creating a New Data Schema or Data Schema Version.
Creating a New Data Schema using the Rhino SDK
Prerequisites
Before starting this process, you should have already created a Project using the Rhino SDK or UI.
Import your Python Dependencies
import rhino_health as rh
from rhino_health.lib.endpoints.data_schema.data_schema_dataclass import (
DataSchemaCreateInput,
SchemaVariables
)
import getpass
NOTE: Remember to change all lines with CHANGE_ME comments above them in all the blocks below!
Log into the Rhino SDK using your FCP Credentials
Your username will be the email address you log into the Rhino FCP platform with.
print("Logging In")
# CHANGE_ME: MY_USERNAME
my_username = "MY_USERNAME"
session = rh.login(username=my_username, password=getpass.getpass())
print("Logged In")Get Supporting FCP Information Needed to Create Your Dataset
At this point, you will need the name of your Project, any dataset's name you would like to use as input, and your previously created Code Object's name. You can also retrieve each object's UUID by following the instructions here: How do I retrieve a Project's, Collaborator's, Data Schema's, Dataset's, Code Object's, or Code Run's UUID?
# CHANGE_ME: YOUR_FCP_PROJECT_NAME
project = session.project.get_project_by_name('YOUR_FCP_PROJECT_NAME')
workgroup = session.project.get_collaborating_workgroups(project.uid)[0][Option 1] Create Your Schema From a File
To create your Data Schema you will need to change several different pieces of information in the code block below. The paths for file_path will be a local path in your development environment.
schema_params = DataSchemaCreateInput(
# CHANGE_ME: SCHEMA_NAME
name = "SCHEMA_NAME",
# CHANGE_ME: SCHEMA_DESCRIPTION
description = "SCHEMA_DESCRIPTION",
primary_workgroup_uid = workgroup.uid,
# CHANGE_ME: FILE_PATH
file_path = "FILE_PATH"
)
schema = session.dataset.create_data_schema(schema_params)
print(f"Created new dataset '{schema.name}' with uid '{schema.uid}'")