Quickstart using CLI
Use GlassFlow CLI to create a pipeline to process incoming data, transform it, and make it available for consumption in real-time.
Prerequisites
To complete the Quickstart you'll need the following:
Python is installed on your machine.
Download and Install Pip to manage project packages.
Install GlassFlow CLI
Install the GlassFlow CLI on macOS using the Homebrew:
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:
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.
Step 2: Install GlassFlow SDK
Install the GlassFlow Python SDK and virtual environment package python-dotenv
using pip
.
Optional: Create a virtual environment before installing Python dependencies. Run the following command:
python -m venv .venv && source .venv/bin/activate
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 Your Pipeline
Run the following command in a terminal to create your pipeline in GlassFlow using the CLI tool.
Once the pipeline is configured successfully, the pipeline becomes active immediately.
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 5: Get Your Pipeline Credentials
Run the following command to retrieve Pipeline ID(Identifier) and Space ID:
You will get a message on the terminal with the Pipeline ID and Space ID:
To get the pipeline access token, run the List Access Tokens CLI command:
Note down the Pipeline ID, Space ID, and Access Token. You'll set them as environment variables in the upcoming section.
Step 6: Create an environment configuration file
Create a .env
file in your project directory with the following content, replacing the placeholders with your actual GlassFlow pipeline credentials:
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:
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:
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
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.
Last updated