Pathway: A Python Framework for Real-Time Data and AI


Pathway: A Python Framework for Real-Time Data and AI

pathwaycom/pathway

2025-08-15

As a software engineer, you'll find Pathway invaluable because it simplifies a lot of the complexities of stream processing. Instead of dealing with low-level details of distributed systems or complex data synchronization, you can focus on the business logic of your application.

Here's why it's a game-changer

Python Native
If you already know Python, you're good to go! Pathway lets you build powerful streaming applications using the familiar syntax and libraries you love.

Automatic Incremental Computation
This is the magic behind Pathway. When new data arrives, it automatically updates the results of your computations efficiently, only processing the new data instead of re-calculating everything from scratch. This makes your applications fast and resource-efficient.

Unified API for Batch and Streaming
You write your code once, and it works for both batch and streaming data. No need to rewrite your logic for different data sources. This simplifies development and maintenance.

LLM and RAG Integration
Pathway provides built-in tools for working with LLMs. You can easily build pipelines that ingest streaming data, process it, and then use it to augment LLM queries in real-time. This is perfect for building intelligent chatbots, recommendation systems, or real-time summarization tools.

Getting started with Pathway is straightforward. You'll need Python installed on your system.

Installation

You can install Pathway using pip

pip install pathway

Writing Your First Pipeline

A Pathway application is a Python script. You import the necessary modules, define your data sources, and then specify the computations you want to perform.

Here's a simple example of a pipeline that reads data from a streaming source, filters it, and then writes the results to an output file.

Imagine you have a stream of log events, and you want to filter out all events that are not of a "CRITICAL" level.

data_stream.csv (simulated streaming data)

Let's assume this file is constantly being appended with new log entries.

timestamp,level,message
2025-08-15T09:00:00Z,INFO,User logged in
2025-08-15T09:01:05Z,CRITICAL,Database connection failed
2025-08-15T09:02:10Z,WARNING,Low disk space

etl_pipeline.py

import pathway as pw

# 1. Define the input data source
# We're simulating a streaming CSV file that new lines are appended to.
log_data = pw.io.csv.read(
    "data_stream.csv",
    mode="stream",
    schema=pw.Schema(
        timestamp=str,
        level=str,
        message=str
    )
)

# 2. Transform the data
# This is where we apply our business logic.
# Here, we filter for only the 'CRITICAL' log entries.
critical_logs = log_data.filter(log_data.level == "CRITICAL")

# 3. Define the output sink
# We'll write the results to a new CSV file.
pw.io.csv.write(critical_logs, "critical_logs_output.csv")

# 4. Run the pipeline
# This starts the computation and keeps it running
# to process new data as it arrives.
pw.run()

When you run this script with python etl_pipeline.py, Pathway will

Continuously monitor data_stream.csv for new lines.

Whenever a new line is added, it will efficiently check if level is "CRITICAL".

If it is, it will append that line to critical_logs_output.csv.

The magic is that this entire process is managed for you in real-time without you needing to manually manage loops, threads, or complex state management. It's a clean, declarative way to build robust data pipelines.

Pathway really shines when you want to build more complex applications, like a real-time RAG system.

Here's a conceptual example of a pipeline that

Ingests a stream of documents (e.g., from a news feed).

Indexes these documents in a vector store.

Takes a user query as input.

Retrieves relevant documents from the vector store in real-time.

Uses the retrieved context to augment a prompt to an LLM.

import pathway as pw
from pathway.xpacks.llm import prompt_llm, ragger
from pathway.xpacks.vector_store import VectorStoreServer

# 1. Ingest a stream of documents (e.g., news articles)
documents = pw.io.csv.read("news_articles.csv", mode="stream")

# 2. Index the documents in a vector store
# This happens automatically and in real-time as new articles arrive.
document_store = VectorStoreServer(
    documents=documents.select(pw.this.text)
)

# 3. Ingest a stream of user queries
queries = pw.io.csv.read("user_queries.csv", mode="stream")

# 4. Use the RAG module to combine queries with retrieved context
# Pathway automatically joins the queries with the relevant documents.
prompted_queries = ragger(
    rag_context=document_store,
    query=queries.query,
    prompt_template="Answer the following question based on the provided context: {query}\n\nContext: {context}"
)

# 5. Send the augmented prompt to an LLM and get the response
llm_responses = prompt_llm(prompted_queries.prompt, model="gpt-4")

# 6. Write the final responses to an output file
pw.io.csv.write(llm_responses, "llm_answers.csv")

# 7. Run the pipeline!
pw.run()

pathwaycom/pathway




High-Performance Algorithmic Trading with Nautilus Trader

At its core, Nautilus Trader is a powerful framework for building and running algorithmic trading strategies. Think of it as a toolkit that provides the essential components you need


Daft Explained: The Python/Rust Distributed Engine for ML Engineers

At its core, Daft is a distributed query engine that's built for modern data science and machine learning workflows. Think of it as a powerful


Building and Scaling LLM Applications with TensorZero

TensorZero is an all-in-one toolkit designed to help you build, deploy, and manage industrial-grade LLM applications. Think of it as a comprehensive platform that covers the entire lifecycle of an LLM app


The Software Engineer’s Guide to Efficient Data Transformation with CocoIndex

CocoIndex is a game-changer here. Think of it as a high-performance bridge between your raw data and your AI applications


Beyond OCR: Boosting RAG Systems with ByteDance's Dolphin Model

The ByteDance Dolphin model is a powerful, multimodal document image parsing model. In simple terms, it's designed to read and understand structured content from document images (like scans or PDFs that have been converted to images), including complex elements such as text paragraphs


From Fundamentals to Interviews: Your Guide to donnemartin/system-design-primer

In a nutshell, donnemartin/system-design-primer is a fantastic, open-source resource designed to teach you how to build robust


The Engineer's Toolkit for Digital Libraries: Getting Started with Calibre

While many people know it as "that desktop app for ebooks, " for us developers, it’s actually a powerful, Python-based toolkit for document manipulation and library management


Level Up Your Apps with yt-dlp Integration

Think of yt-dlp as a super-powered command-line tool for downloading audio and video from countless websites, not just YouTube


Poetry: The Modern Python Package Manager

Hello there! As a fellow software engineer, I'm excited to talk about Poetry. It's a fantastic tool that makes managing Python projects a whole lot easier


The Software Engineer's Guide to theHarvester

From a software engineer's perspective, theHarvester is a powerful tool forSecurity Audits and Penetration Testing Before you can defend your application