Data Blocks Development Guidelines

      Data Blocks Development Guidelines


        Article summary

        How to Download Data Blocks, Develop Code in Visual Studio Code, Unit Test, and Upload to the Data Block Editor

        Please do ensure that the Python, Visual Studio Code and PyTest are setup correctly in your working environment.

        Step 1: Log into the Assette App

        - First, log into the Assette App and navigate to the Developer Center.

        A screenshot of a computer

        Step 2: Access Data Block Editor

        - Click on the "Data Block Editor" tab and either create a new data block or open an existing one. For this guide, we'll use "DEMO_TopBottomNHoldings."

        A screenshot of a computer  Description automatically generated

        Step 3: Save Data Block

        - Ensure the definition section contains some Python code and add any necessary dependencies and metadata. Save the data block.

        Step 4: Download the Data Block

        - Confirm that the block type is "Python"

        A screenshot of a computer  Description automatically generated - Then click the download button. Only Python blocks allow the Download and Upload functionalities.

        A screenshot of a computer  Description automatically generated

        Step 5: Extract Files

        - Extract the downloaded zip file containing files related to unit testing. A sample folder is shown below.

        A screenshot of a computer  Description automatically generated

        - Below is a breakdown of the folders:

        a. Data: Contains JSON files with data from dependency blocks.

        b. Python_blocks: Contains the data block created.

        c. Unit_test: Contains Python file for unit testing the created block.

        d. Readme.txt: Instructions for setting up the local environment with a virtual Python environment and installing necessary Python libraries.

        e. Requirements.txt: List of Python libraries to be installed.

        Step 6: Setup Visual Studio Code

        - Open Visual Studio Code and load the project folder.

        A screenshot of a computer  Description automatically generated

        Step 7: Prepare Dependency Data

        - Before proceeding further, it's crucial to ensure that the necessary data from the dependency blocks are added into the JSON files. In this case, the primary dependency blocks for the "DEMO_TopBottomNHoldings" block are "demo_snowflakegetportfoliobasecurrency" and "demo_snowflakeholdingsdetailsextract", found in the “data” folder, each requiring a dedicated JSON file. The “demo_snowflakegetportfoliobasecurrency” data block will be used as an example.

        To incorporate data into these dependency blocks, follow these steps:

        1. Execute the dependency blocks to generate the required output data.

        A screenshot of a computer  Description automatically generated
        1. Copy the content enclosed within the rectangular braces from the output.

        A screenshot of a computer  Description automatically generated
        1. Replace the empty rectangular braces within the corresponding JSON files with the copied content and save it.

        A screenshot of a computer  Description automatically generated

        By completing these steps, the dependency data will be successfully integrated into the JSON files, ensuring that the dependency data is set up properly.

        Step 8: Edit Data Block Code

        - Open the Python file in the `Python_blocks` folder and edit the code. As seen below, the content inside the execute function reflects the definition section inside the datablock. Please note that there is an additional indentation needed when editing code in visual studio code. Incorrectly adding the indentation may cause the block to fail when the block needs to be uploaded into the data block editor.

        A screen shot of a computer  Description automatically generated

        Step 8: Set Up Unit Testing

        **Before progressing to this step, all the required Python libraries must be installed along with the PyTest extension and the correct Python version.

        - Click on the flask icon (Pytest)

        A screenshot of a computer  Description automatically generated

        - Click on "Configure Python Tests"

        A screenshot of a computer  Description automatically generated

        -Click on "Pytest"

        A screenshot of a computer  Description automatically generated

        - Select the root folder (or the venv folder, if the virtual python environment is used).

        A screenshot of a computer  Description automatically generated

        - Now the tests should show up as shown in the image below, along with the unit test python file.

        A screenshot of a computer  Description automatically generated

        - For this example, the unit testing file needs to be set up with the correct testing parameters and a unit test.

        - As seen below, the parameters section consists of the same parameters that are used for the data block. Then to test conditions for the data block, assert statements can be used to write unit tests.

        A screen shot of a computer program  Description automatically generated

        Step 9: Run Unit Tests

        - Run the unit tests using Pytest by clicking the “Run Test” button in the Pytest extension, as shown below.

        A screen shot of a computer  Description automatically generated

        Step 10: Using debug mode in Pytest.

        - To debug the python code, a breakpoint needs to be added in the main Python data block in the Python_blocks folder. A breakpoint can be added by hovering the cursor over any line of the code as shown below. Several breakpoints can be added as needed.

        A screenshot of a computer program  Description automatically generated

        -Once a breakpoint is added, click on the Pytest extension and click on “Debug Test”.

        A screenshot of a computer  Description automatically generated

        - Now the debug mode will be enabled and provide insights into the code as shown below.

        A screenshot of a computer  Description automatically generated

        - In the Debug mode, there are several tabs, which are explained below.

        a. Variables: The variables section consists of “Local” and “Global” variables that are used by the python script. This window will preview the current results of all the variables that are available at the breakpoint.

        b. Watch: The watch option allows to select specific variables to monitor.

        c. Callstack: Shows the functions that are called until the breakpoint.

        Step 11: Upload to Data Block Editor

        - Once the Data Block is developed, save the block.

        - In the Data Block Editor, open the data block (for this example DEMO_TopBottomNHoldings), navigate to the definition section, and click "Upload."

        - Select the Python file from the “Python_blocks” folder. Now the data block is successfully uploaded.

        Step 12: Save and Preview

        - Save the data block and preview to test code changes and the results. Once results are correct, publish the data block.