Quickstart using CLI

A quickstart guide to run GlassFlow, create your first pipeline using CLI, produce and consume data.

Prerequisites

To complete the Quickstart you'll need the following:

  1. Python is installed on your machine.

  2. Download and Install Pip to manage project packages.

Install GlassFlow CLI

Install the GlassFlow CLI on macOS using the Homebrew:

brew tap glassflow/tap && brew install glassflow

You can also install the CLI using other installation options on Linux/Windows.

Create a GlassFlow account

To initiate the signup process via the GlassFlow CLI, run the following command:

glassflow signup

Follow the sign-up steps, after successfully creating an account, you are ready to create a new pipeline.

Creating Your First Pipeline

Step 1: Setup Project

Start by creating a dedicated project folder. Create a directory for this project named glassflow-playground, where you will place all the necessary files.

mkdir glassflow-playground && cd glassflow-playground

Step 2: Install GlassFlow SDK

Install the GlassFlow Python SDK using pip.

Optional: Create a virtual environment before installing Python dependencies. Run the following command: python -m venv .venv && source .venv/bin/activate

pip install glassflow

Step 3: Create a Transformation Function

Create a new file transform.py and write a short Python code that transforms incoming data. The function you write will parse the incoming JSON data, convert product quantities based on unit measurements, and categorize product items.

Note that the handler function is mandatory to implement in your code. Without it, the running transformation function will not be successful.

You can also import other Python dependencies (packages) in the transformation function. See supported libraries with GlassFlow.

Step 4: Create a New Space

Create a new space with <space_name> where one or more pipelines are contained.

glassflow space create quickstart

After creating the space successfully, you will get a SpaceID in the terminal.

Step 5: Create a Pipeline

Run the following command in a terminal to create your pipeline inside the space using the CLI tool.

glassflow pipeline create inventorymanagement --space-id=<your_space_id> --function=transform.py

After running the command, it returns a new Pipeline ID with its Access Token and the pipeline becomes active immediately. Note down the Pipeline ID and Access Token. You'll set them as environment variables in the upcoming section.

Important: Now the transformation function is deployed and running on GlassFlow’s Serverless Execution Engine in the cloud, and you do not need to configure or maintain any infrastructure on your side.

Step 6: Get Your Pipeline Credentials (Optional)

You can also retrieve pipeline credentials with easy steps. Run the following command to retrieve Pipeline ID(Identifier):

glassflow pipeline list

You will get a message on the terminal with the Pipeline ID and Space ID:

ID                                   | Name                     | Space ID                             | Space Name     |
-------------------------------------------------------------------------------------------------------------------------
9c43996a-2702-4f33-a0c2-711b4d18a7f6 | inventorymanagement      | 07409e3b-bad6-414d-a69c-0f2ce5a14982 | main           |

To get the pipeline access token, run the List Access Tokens CLI command:

glassflow pipeline tokens {pipeline_id}
Name    | ID                                   | Token     |
------------------------------------------------------------
default | 84b61c1c-0a92-4c2d-a1de-591793b12c30 | **********|
------------------------------------------------------------

Step 7: Set environment variables

Set environment variables with your actual GlassFlow pipeline credentials such as PIPELINE_ID and PIPELINE_ACCESS_TOKEN:

export PIPELINE_ID=your_pipeline_id
export PIPELINE_ACCESS_TOKEN=your_access_token

After running these commands, the environment variables PIPELINE_ID and PIPELINE_ACCESS_TOKEN will be available to your application allowing it to connect to your GlassFlow pipeline from the client SDK.

Sending Data to Your Pipeline

Now you can start sending data to the pipeline. GlassFlow will automatically run your transformation function on each event entering the pipeline and make your transformed data available in milliseconds.

Create a new Python file in your project root directory called producer.py. Write a script to read auto-generated inventory data and send it to the GlassFlow pipeline. Copy and paste the following code to producer.py file:

Run the above Python script with the following command in your terminal:

python producer.py

When you run the above script, on every event that enters the pipeline, GlassFlow will invoke the transformation function that you have defined in the inventorymanagement. In this case, it will run the transform.py file and transform every raw data you send to the pipeline.

Consuming Data from Your Pipeline

Create a new Python file called consumer.py. The consumer is responsible for pulling transformed data from the pipeline. It continuously checks for new data, processes it as needed, and acts upon the transformed information. Copy and paste the following code to consumer.py the file:

Run the above Python script consumer.py in a separate terminal window to see the output side-by-side:

python consumer.py

Now you activated the consumer side of the pipeline. This consumer.py script retrieves the processed data from the pipeline in real-time and you will see the results of data transformation written to a new local file called (supplier_inventory.txt).

You can watch the new transformations by running the following command on a different terminal window


tail -f supplier_inventory.txt

Congratulations! You've set up a real-time inventory management system pipeline using GlassFlow.

Conclusion

In this Quickstart you've learned the following:

  • How to install GlassFlow and set up a new project.

  • How to create a data pipeline using the GlassFlow CLI.

  • How to implement transform function and process data in real-time.

  • How to publish data into the pipeline.

  • How to consume data from the pipeline.

Next

Explore the tutorials section to help you master real-time data streaming and processing with GlassFlow.

Use CasesIntegrations

Last updated

Logo

© 2023 GlassFlow