Package: labelsnow
Labelbox Connector for SnowflakeAccess the Labelbox Connector for Snowflake to connect an unstructured dataset to Labelbox, programmatically set up an ontology for labeling, and load the labeled dataset into your Snowflake environment.Labelbox is the enterprise-grade training data solution with fast AI enabled labeling tools, labeling automation, human workforce, data management, a powerful API for integration & SDK for extensibility. VisitLabelboxfor more information.This library is currently in beta. It may contain errors or inaccuracies and may not function as well as commercially released software. Please report any issues/bugs viaGithub Issues.Table of ContentsRequirementsInstallationDocumentationAuthenticationContributionRequirementsSnowflake account with credentialsSnowflake SDKLabelbox accountGenerate a Labelbox API keyInstallationInstall LabelSnow to your Python environment. The installation will also add the Labelbox SDK, a requirement for LabelSnow to function. LabelSnow is available via pypi:pip install labelsnowDocumentationLabelSnow includes several methods to help facilitate your workflow between Snowflake and Labelbox.Create your dataset in Labelbox from your Unstructured Data stage in Snowflake:sf_dataframe = labelsnow.get_snowflake_datarows(snowflake_cursor, "name_of_snowflake_stage", 604800) #604800 is signed_URL expiration time in Snowflake

my_demo_dataset = labelsnow.create_dataset(labelbox_client=lb_client, snowflake_pandas_dataframe=sf_dataframe, dataset_name="SF Test")Where "sf_dataframe" is a pandas dataframe of unstructured data with asset names and asset URLs in two columns, named "external_id" and "row_data" respectively. my_demo_dataset labelsnow.create_dataset() returns a Labelbox Dataset python object.external_idrow_dataimage1.jpghttps://url_to_your_asset/image1.jpgimage2.jpghttps://url_to_your_asset/image2.jpgimage3.jpghttps://url_to_your_asset/image3.jpgGet your annotations from Labelbox as a Pandas DataFrame.bronze_df = labelsnow.get_annotations(lb_client, "insert_project_id_here")You can use the our flattener to flatten the "Label" JSON column into component columns, or use the silver table method to produce a more queryable table of your labeled assets. Both of these methods take in the bronze table of annotations from above:flattened_table = labelsnow.flatten_bronze_table(bronze_df)
queryable_silver_DF =labelsnow.silver_table(bronze_df)Depositing your tables into SnowflakeWe also include a helper functionput_tables_into_snowflakethat can help you quickly load Pandas tables into Snowflake. It takes in a dictionary of Pandas tables, creates tables, and loads the data.my_table_payload = {"BRONZE_TABLE": bronze_df,
                    "FLATTENED_BRONZE_TABLE": flattened_table,
                    "SILVER_TABLE": silver_table}
                    
ctx = snowflake.connector.connect(
        user=credentials.user,
        password=credentials.password,
        account=credentials.account,
        warehouse="name_of_warehouse",
        database="SAMPLE_DB",
        schema="PUBLIC"
    )

labelsnow.put_tables_into_snowflake(ctx, my_table_payload)How To Get Video Project AnnotationsBecause Labelbox Video projects can contain multiple videos, you must use theget_videoframe_annotationsmethod to return an array of Pandas DataFrames for each video in your project. Each DataFrame contains frame-by-frame annotation for a video in the project:video_bronze = labelsnow.get_annotations(lb_client, "insert_video_project_id_here") #sample completed video project
video_dataframe_framesets = labelsnow.get_videoframe_annotations(video_bronze, LB_API_KEY)You may use standard Python code to  iteratively to create your flattened bronze tables and silver tables:silver_video_dataframes = {} 

video_count = 1
for frameset in video_dataframe_framesets:
    silver_table = labelsnow.silver_table(frameset)
    silver_table_with_datarowid = pd.merge(silver_table, video_bronze, how = 'inner', on=["DataRow ID"])
    video_name = "VIDEO_DEMO_{}".format(video_count)
    silver_video_dataframes[video_name] = silver_table_with_datarowid
    video_count += 1Then deposit these Pandas dataframes into Snowflake withput_tables_into_snowflakeWhile using LabelSnow, you will likely also use the Labelbox SDK (e.g. for programmatic ontology creation). These resources will help familiarize you with the Labelbox Python SDK:Visit our docsto learn how the SDK worksView ourLabelSnow demo codefor inspiration.view ourAPI reference.AuthenticationLabelbox uses API keys to validate requests. You can create and manage API keys onLabelbox.ContributionPlease consultCONTRIB.md