Developing QuixStreams Applications Locally with Quix CLI
Debugging an application locally using quix run
has some nuances that need to be properly explained. This tutorial will guide you through the process of debugging an application of an existing Quix data pipeline using a local broker and the Quix CLI. We'll cover prerequisites, best practices, and common issues.
Prerequisites
This tutorial assumes that you have read the Quickstart and installed the dependencies:
Tip
If you want to start developing after cloning a repository, run:
This will generate all the necessary files to get you started.
Developing with Quix CLI
Step 1: Setting Up the Broker
Note
If you followed all the steps from the Quickstart tutorial, your local pipeline broker is already up and running.
Depending on your setup, you can choose to use your local pipeline broker, another local broker, or the Quix Cloud broker. Here are the steps to configure each:
To use your local pipeline broker, start it using:
This will spin up a local broker running on localhost:19092
.
How to ensure that your local application is pointing to your local pipeline broker?
The SDK Broker configuration is the broker you use when you run the application locally outside the pipeline.
Verify it by running:
Look for this line:
If you see something else and want a quick fix, run:
If you want to use a different local broker, you can set the broker address manually. This is useful if you have another Kafka broker running on your local machine or elsewhere. To set a custom local broker address, run:
If you don't want to run the interactive version, you can specify the parameters and enable it by running:
Tip
If you had previously set your broker to Quix Cloud, you will need to switch it back to the local broker. Run:
For more details on the set
command, refer to the set broker documentation.
Warning
This doesn't change your local pipeline broker, just the broker you use when you run the application locally outside the pipeline.
To use the Quix Cloud broker, set the SDK broker configuration to Quix Cloud. This will configure your environment to use the Quix Cloud infrastructure for debugging:
This configuration is ideal if you want to test your application in an environment that closely resembles production.
For more details on the cloud
command, refer to the cloud broker documentation.
Warning
This doesn't change your local pipeline broker, just the broker you use when you run the application locally outside the pipeline.
For a comprehensive overview of all SDK broker commands, refer to the SDK broker documentation.
Step 2: Preparing Your Local Environment
To ensure your application runs smoothly across different environments, it's essential to create a virtual environment for each application you develop. This isolates the dependencies for each application, avoiding conflicts between them.
Create a Virtual Environment
Navigate to your application's directory and run one of the following command:
Note
Depending on your system configuration, the command might differ slightly. Use one of these alternatives if needed:
or
This command sets up a virtual environment named .venv
inside your application's directory.
Activate the Virtual Environment
After creating the virtual environment, you need to activate it to start using it for your application. The activation command varies by operating system:
Install Dependencies
Once the virtual environment is active, you can install your application's dependencies from the requirements.txt
file. Run the following command:
This ensures all necessary packages are installed specifically for this application.
Using DevContainers
If you prefer using DevContainers for an isolated development environment, you can set them up with the --devcontainer
option:
The devcontainer.json
file is automatically generated. It reuses your existing Dockerfile, installs Python and Docker extensions, and sets up the Quix CLI within the dev container. This setup ensures that your development environment matches your production environment, reducing the "it works on my machine" issues.
By using DevContainers, you ensure that your development environment is consistent, isolated, and reproducible.
Your IDE will take care of the rest.
Step 3: Understanding Application Variables
Let's take a look at the .env
file generated for the event-detection-transformation
application:
Note
If you didn't follow the Quickstart you can get to this point by running:
or, you can get this .env
file updated at any point for any Quix applications by running:
# ======================================================
# 🚀 Quix CLI guidelines 🚀
# ======================================================
# To update the quix.yaml from this .env file, use:
# 🔄 quix pipeline update
#
# To update the .env file from the quix.yaml file, use:
# 🔄 quix init --update
# ======================================================
### Quix SDK Configuration ###
# Configuration settings for QuixStreams
Quix__Broker__Address=localhost:19092
### Input Topics ###
# Define the input topics used by the application
input=f1-data
### Output Topics ###
# Define the output topics used by the application
output=hard-braking
### Secrets ###
# Sensitive information such as API keys and passwords
### Free Text ###
# Add any free text or comments here
### Untracked Variables ###
# Variables that are not tracked by Quix CLI
You can create and remove variables for your local applications here at your discretion, and they will be integrated into the system as needed.
Step 4: Running Your Code with quix run
By using the quix run
command, the .env
variables are injected into your Python code as environment variables so you can read the values like this:
import os
...
input_topic = app.topic(os.environ["input"])
output_topic = app.topic(os.environ["output"])
Working with a local pipeline
The --stop
or --intercept
options can be used to stop or pause the deployed version of your application during the execution of this command.
Note
The sample provides support for the load_dotenv
library, which is useful if you want to run Python directly or if your IDE doesn't automatically load .env
files.
Step 5: Updating Your Pipeline from Your Local Variables
Now, you can create new variables by simply adding them to the appropriate section of the .env
file:
# ======================================================
# 🚀 Quix CLI guidelines 🚀
# ======================================================
# To update the quix.yaml from this .env file, use:
# 🔄 quix pipeline update
#
# To update the .env file from the quix.yaml file, use:
# 🔄 quix init --update
# ======================================================
### Quix SDK Configuration ###
# Configuration settings for QuixStreams
Quix__Broker__Address=localhost:19092
### Input Topics ###
# Define the input topics used by the application
input=f1-data
### Output Topics ###
# Define the output topics used by the application
output=hard-braking
### Secrets ###
# Sensitive information such as API keys and passwords
### Free Text ###
# Add any free text or comments here
variable=my-value
### Untracked Variables ###
# Variables that are not tracked by Quix CLI
To move your local variables to your pipeline, run:
Your quix.yaml
file will now contain the new variable you created:
- name: event-detection-transformation
application: event-detection-transformation
version: latest
deploymentType: Service
resources:
cpu: 200
memory: 800
replicas: 1
variables:
- name: input
inputType: InputTopic
required: false
value: f1-data
- name: output
inputType: OutputTopic
required: false
value: hard-braking
- name: variable
inputType: FreeText
required: false
value: my-value
Step 6: Updating Your Local Variables from Your Pipeline
If your quix.yaml
file contains values you want to use locally, run:
This is helpful when you merge remote changes from git and the variable values have changed.
- name: event-detection-transformation
application: event-detection-transformation
version: latest
deploymentType: Service
resources:
cpu: 200
memory: 800
replicas: 1
variables:
- name: input
inputType: InputTopic
required: false
value: deployed-input-topic
- name: output
inputType: OutputTopic
required: false
value: deployed-output-topic
- name: variable
inputType: FreeText
required: false
value: a-pipeline-value
# ======================================================
# 🚀 Quix CLI guidelines 🚀
# ======================================================
# To update the quix.yaml from this .env file, use:
# 🔄 quix pipeline update
#
# To update the .env file from the quix.yaml file, use:
# 🔄 quix init --update
# ======================================================
### Quix SDK Configuration ###
# Configuration settings for QuixStreams
Quix__Broker__Address=localhost:19092
### Input Topics ###
# Define the input topics used by the application
input=deployed-input-topic
### Output Topics ###
# Define the output topics used by the application
output=deployed-output-topic
### Secrets ###
# Sensitive information such as API keys and passwords
### Free Text ###
# Add any free text or comments here
variable=a-pipeline-value
### Untracked Variables ###
# Variables that are not tracked by Quix CLI
Other useful commands for Local Development
There are several other CLI commands that you may find very useful during your local development. Here are some of the most relevant ones:
- quix pipeline view: Create and preview a mermaid diagram of the pipeline.
- quix pipeline up: Run your pipeline locally using docker compose
- quix pipeline status: Display the current status of the local pipeline
- quix pipeline logs -f -n 10: View output from deployments of the local pipeline in realtime
- quix pipeline sync: Synchronize your local pipeline to Quix Cloud
- quix broker topics read: Read the messages from your pipeline topics
You should also check our CLI Commands Summary, where you'll find the most useful commands for developing QuixStreams data pipelines locally.
Next steps
-
Time to level up?
Deploy your local pipeline to the Cloud, for scalability, observability, and even more Quix magic.