Resource Creator

Python script for the uploading of resources with property values and components to the Riffyn Library using the API.

Description

This script takes an Excel or CSV file as input, parses the resource data in the file, and assigns the authenticated user as the owner of the resources.

Entities supported for upload:

  • Resource Types
  • Property Types
  • Components

Excel columns are order-sensitive. Specific header keywords are required for columns. Labels are case-sensitive.

 

Prerequisites

  • .csv or .xlsx file located in a folder named 'csv'
  • Python package from the Riffyn SDK
  • Login credentials for authenticated user

 

Setup

  1. Install the python package from the Riffyn SDK
  2. Install via Setuptools.
  3. Run this command in the command line at the root of your folder:
    python setup.py install --user (or sudo python setup.py install to install the package for all users)

 

Configuration

The script should be updated before use to point to the API service of your Riffyn instance.

At the top of the Resource_creator.py file, set the 'host' variable to the address of your library (host="https://api.riffyn.com"). If you use Riffyn's multi-tenant cloud the service is: api.riffyn.com.

If your company has it's own VPC it will be in the format: api.yourcompany.riffyn.com

 

Format for .xlsx & .csv Files

The columns must be in a specific order for the script to parse the data correctly.

The first 3 columns must have a header names for resource information being added to the library - 'Resource Name', 'Resource Type', and 'Resource Description'. All columns after these first 3 must be either a combination of components and properties of just properties.

Columns with property information are identified by header names which do not contain a pipe symbol (|) or key-words. Only fixed/mutable properties will be retained.

Columns with component information are identified by header names which contain a pipe symbol (|). The component name must be listed to the left of the pipe symbol (|) and properties listed to the right. Components and Resource Types must already exist in Riffyn or be added manually at the prompt.

Each Resource to be added requires:

  • Resource Name (header "Resource Name") - name of the new resource.
  • Resource Type Name (header "Resource Type") - name of the resource type for the new resource. The resource type must already exist in Riffyn or be added manually at the prompt.
  • Resource Description (header "Resource Description") - description of the resource.
  • Property Name (user defined property name header without pipe (|) symbol) - name of property. Must be immutable to be added to the resource.
  • Components & Properties (user defined component and property name header with pipe (|) symbol) - components and component property names. Components must exist in the database or be added manually at the prompt.

File Format: - see example xlsx file at the bottom of this article.

 

Resource Name

Resource Type

Resource Description

Property Name

Component Name | Property Name

1st Resource Name

1st Resource Type Name

1st Resource Description

1st Property Value

1st Component Property Value

2nd Resource Name

2nd Resource Type Name

2nd Resource Description

2nd Property Value

2nd Component Property Value

 

Running the script 

In the command line run:

python resource_creator.py name_of_upload_file

The script will prompt you to enter your login credentials for Riffyn.

The credentials will be masked when typed.

  • username: name@domain.com
  • password: your password

The script will indicate if the login has been successful before proceeding.

 

Script Functionality Details

Once the script starts executing, it will extract the information from each row of the Excel file and print the data to the terminal to allow the data to be reviewed.

Simultaneously, it will query to the library to see if any of the entities already exist in the library. If any pre-existing entities are found, an alert will occur.

The script will ignore pre-existing entities and upload all the data in the file, thus creating duplicates.

A prompt will appear to create missing components and resource types before the upload begins. Components must be created to proceed with the upload and require entry of the name of an existing resource type and other relevant info, while adding missing Resource Types is optional.

Required field for manual upload of components and resource types:

  • Resource Type name - identifier of the parent resource type

If there are multiple resource types with the same name, they will be displayed as options from which the appropriate resource type can be selected by id. Resource type names that are not in Riffyn cannot be added. It will continue with prompts for the other remaining fields, which are optional.

Optional fields:

  • Synonyms
  • Definition
  • Property Name (must exist in Riffyn)

If uploading is successful, it will print the IDs of the added entity in the terminal for lookup using the Riffyn user interface.

If there is a failure, it will provide a log of the errors in the script output.

 

Expected Results

The script will add the resources from the file to the library with its associated attributes (Resource Type, Description, Fixed Properties and their values, Components and their fixed properties and values). The terminal will display the name of the entity as it is uploaded with the associated attributes and the generated database id.

If you need assistance please contact Riffyn at support@riffyn.com.

 

Script Logic Overview

  • login
  • convert xlsx to csv file conversion
  • read file
  • check for existing entities in the database
  • Prompt the user to the missing components
  • Generate the info for the component
  • Prompt the user to the missing resource types
  • Generate the info for the resource type
  • upload of resources to the database
  • feedback on upload

 

Downloads

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request