Pathway 入门指南:用 Python API + Rust 引擎构建实时流式 ETL 与 RAG 管道

发布时间:2026/9/4 9:07:09
Pathway 入门指南:用 Python API + Rust 引擎构建实时流式 ETL 与 RAG 管道 Pathway 入门指南用 Python API Rust 引擎构建实时流式 ETL 与 RAG 管道【免费下载链接】pathwayPython ETL framework for stream processing, real-time analytics, LLM pipelines, and RAG.项目地址: https://gitcode.com/GitHub_Trending/pa/pathway本文基于 Pathway 官方开发者文档首页 welcome.md 展开系统介绍 Pathway Live Data Framework 的定位、安装方式与全部 11 项核心特性并结合仓库中的pyproject.toml、Python API 入口与 Rust 引擎源码逐条佐证其实现依据。读完本篇你将掌握 Pathway 的完整安装与依赖分组、首个实时管道代码的运行方式以及每一项框架特性在源码中的落点。一、什么是 Pathway Live Data FrameworkPathway Live Data Framework 是一个面向数据流data streams的 Python 数据处理框架专为分析与 AI 管道设计。文档首页给出的定位非常明确它是流式处理场景的理想选择适用于实时流式 ETLstreaming ETL、面向非结构化数据的 RAG 管道等实时处理用例项目描述将其概括为用于流处理、实时分析、LLM 管道与 RAG 的 Python ETL 框架见 README.md。也就是说你用惯常的 Python 写法声明“读取数据 → 转换 → 写出结果”而数据更新、乱序补算、增量维护这些流式框架最麻烦的部分由底层引擎自动处理。仓库中 README.md 进一步说明了它的三个工程承诺同一份代码可同时用于本地开发、CI/CD 测试、批处理作业、流回放与实时流计算全量驻留内存便于用 Docker/Kubernetes 部署Python 代码实际由 Rust 引擎驱动执行从而实现多线程、多进程乃至分布式计算。二、快速安装pip install pathway及其依赖分组文档首页给出的最简安装方式就是一条命令pip install pathwayREADME.md 中推荐带升级标志的等价形式pip install -U pathway。它会安装运行管道所需的全部基础依赖包括 Rust 引擎本体。2.1 运行环境前提Python 版本pyproject.toml 声明requires-python 3.10即要求 Python 3.10 及以上操作系统官方仅在macOS 与 Linux上提供支持README.md 与 Installation 文档 均有提示Windows 用户需借助 WSL、Docker 或虚拟机安装完成后import pathway as pw即可使用无需额外服务。2.2 可选依赖组extrasInstallation 文档 将依赖拆分为若干组以便按需安装pyproject.toml 的[project.optional-dependencies]表是这些分组的权威定义。常用分组如下分组安装命令说明Basic LLM Toolingpip install pathway[xpack-llm]常见 LLM 库OpenAI、LiteLLM、LangChain、LlamaIndex 等Local LLM Deploymentpip install pathway[xpack-llm-local]本地模型推理sentence-transformers、transformersParsing Documentspip install pathway[xpack-llm-docs]文档解析docling、python-docx、unstructured、pdf2image 等Airbyte Connectorpip install pathway[airbyte]接入 Airbyte可扩展至数百种数据源SharePoint Connectorpip install pathway[xpack-sharepoint]SharePoint 读写需要免费 license keyAllpip install pathway[all]安装全部可选包从 pyproject.toml 可以确认xpack-llm组实际包含 openai、litellm、langchain、llama-index-core/retrievers、instructor、google-generativeai 等并附带大量版本上限与兼容性注释xpack-sharepoint组仅新增Office365-REST-Python-Client一个依赖。多个分组可一次性安装例如pip install pathway[xpack-llm, airbyte]。基础依赖方面pyproject.toml 还声明了 pandas、numpy、pyarrow、pydantic、boto3、sqlalchemy/deltalake以及OpenTelemetry 全家桶opentelemetry-api / sdk / exporter-otlp-proto-grpc——这正是文档首页声称“fully compatible with OpenTelemetry”的直接依赖依据。三、第一个实时管道从 README 示例开始运行README.md 给出了一段最小可运行的实时计算示例——实时统计输入中非负值的总和import pathway as pw # Define the schema of your data (Optional) class InputSchema(pw.Schema): value: int # Connect to your data using connectors input_table pw.io.csv.read( ./input/, schemaInputSchema ) #Define your operations on the data filtered_table input_table.filter(input_table.value0) result_table filtered_table.reduce( sum_value pw.reducers.sum(filtered_table.value) ) # Load your results to external systems pw.io.jsonlines.write(result_table, output.jsonl) # Run the computation pw.run()这段代码体现了 Pathway 的三段式心智模型connector 读入 → Table 变换filter/reduce/join/groupby…→ connector 写出最后用一行pw.run()启动计算。仓库中 python/pathway/init.py 证实了 API 面的完整性顶层导出了run、groupby、join系列inner/left/right/outer、reducers、Schema、udf/apply_async等原语以及stateful、statistical、temporal、graphs、indexing、ml等标准库模块。3.1 启动方式直接当作普通 Python 脚本运行$ python main.py或使用官方 CLI$ pathway spawn python main.py该命令入口在 pyproject.toml 中注册为pathway pathway.cli:main对应实现见 python/pathway/cli.pyPathway 原生支持多线程指定线程数即可并行化$ pathway spawn --threads 3 python main.py运行时自带监控仪表盘web dashboard可查看各 connector 的消息数、系统延迟与日志对应源码目录 python/pathway/web_dashboard。3.2 开箱模板文档首页的“Try Our Templates”卡片指向 RAG 与 ETL 两类可直接运行的模板在本仓库中examples/templates 提供了模板骨架examples/notebooks45 个 notebook与 examples/projects 收录了完整示例工程可作为“跑通自己的数据”的起点。四、核心特性逐条解析文档声明与源码证据文档首页列出了 11 项 Key Features。下面逐条对照仓库源码说明每一项“从哪里来”。4.1 易用的纯 Python API声明“Pathway fully compatible with Python. Use your favorite Python tools and ML libraries.”从 python/pathway/init.py 可见框架不要求你学习新语言任何 Python 函数都可以通过udf/apply注入管道udfs模块还提供 pandas、polars 等库的预置包装器如pandas_transformer、AsyncTransformer。pyproject.toml 中 pandas、numpy、scikit-learn、networkx 等作为硬依赖预装即官方预期你会在管道内直接调用主流 Python/ML 生态。4.2 可扩展的 Rust 引擎无 JVM、无 GIL 限制声明“your Python code is run by a powerful Rust engine with multithreading and multiprocessing. No JVM and no GIL!”仓库结构直接印证了这一点顶层 src/ 目录是 Rust 引擎源码src/lib.rs 为 crate 入口另有engine/计算引擎、persistence/状态持久化、python_api/Python 绑定、connectors/Rust 侧连接器、async_runtime.rs异步运行时等模块pyproject.toml 的[tool.maturin]段声明module-name pathway.engine即 Python 端的pathway.engine是一个由 maturin 构建的 Rust 扩展模块——这就是“Python 代码交给 Rust 引擎执行”的物理载体引擎的算法内核 Differential Dataflow 与调度内核 Timely Dataflow 以源码形式内嵌在仓库 external/differential-dataflow 与 external/timely-dataflow 目录中约 260 个 Rust 源文件可直接阅读。4.3 有状态算子与增量计算声明“use stateful and temporal operations such as groupby and windows” 以及 “using Differential Dataflow, Pathway takes care of out-of-order data points for you, in real time.”Python 侧pw.groupby、GroupedTable在 python/pathway/init.py 中导出pathway.stdlib提供stateful状态化变换、temporal时间窗口、statistical、ordered等模块覆盖 groupby/窗口/排序类需求引擎侧Differential Dataflow 的差分difference语义是增量计算的根基——数据到达时只计算“变化量”而非全量重算因此迟到的、乱序的数据点会在到达时触发结果更新。README.md 对一致性的表述是Pathway 帮你管理时间time managementlate/out-of-order 数据到来时系统会更新既有结果。4.4 批与流一体Batch and streaming alike声明“use the same pipeline on static data and live data streams.”同一管道代码既消费静态文件如示例中的pw.io.csv.read(./input/)也消费持续变化的数据源。README 强调同一份代码可用于“local development, CI/CD tests, running batch jobs, handling stream replays, and processing data streams”。仓库中还有专门文档展开这两种模式的区别Streaming and Static Modes 与 Batch Processing。关于一致性等级需要区分两个文档口径文档首页在特性列表中将“Exactly once consistency批/流结果一致”列为核心能力而 README.md 的 Features 一节表述更精确——免费版提供 at-least-once 一致性企业版提供 exactly-once 一致性。在评估生产部署时应以后者为准。4.5 内存数据处理与低延迟声明“In-memory data processing: real-time updates, reduced latency, and higher throughput.”README.md 说明“all the pipeline is kept in memory”整个管道状态常驻内存更新以增量方式在内存中完成这是低延迟实时更新的直接原因。4.6 部署Docker / Kubernetes / OpenTelemetry声明“Easy to deploy with Docker or Kubernetes. The Pathway Live Data Framework comes with an orchestrator and is fully compatible with OpenTelemetry.”Docker官方镜像pathwaycom/pathway可用如下 Dockerfile 构建应用摘自 README.mdFROM pathwaycom/pathway:latest WORKDIR /app COPY requirements.txt ./ RUN pip install --no-cache-dir -r requirements.txt COPY . . CMD [ python, ./your-script.py ]docker build -t my-pathway-app . docker run -it --rm --name my-pathway-app my-pathway-app对于单文件脚本也可直接挂载执行docker run -it --rm --name my-pathway-app -v $PWD:/app pathwaycom/pathway:latest python my-pathway-app.py仓库中 examples/projects 收录了多个带 Dockerfile 的示例工程可参考其实际写法。OpenTelemetry依赖层面由 pyproject.toml 中固定的 opentelemetry api/sdk/grpc-exporter 三件套保证Python API 层还有set_monitoring_config用于配置监控在 python/pathway/init.py 中导出。Kubernetes/云README 说明容器化后的应用适合 K8s 部署企业版支持分布式 K8s 部署与外部持久化仓库中 integration_tests/ 下还有 kafka、airbyte、s3、iceberg 等方向的集成测试可视为各连接器在真实环境中的验收用例。4.7 持久化与回填Persistence and backfilling声明“save the state of the computation to quickly resume after a failure or a pipeline update.”该能力在仓库中有清晰的双层实现Python 侧 python/pathway/persistence 模块封装持久化 APIRust 侧 src/persistence 目录负责状态存储的具体实现。README 将其定位为“pipeline 在更新或崩溃后可重启”的保障机制。注意文档首页对“exactly once”与“persistence”是并列为两项特性前者关注批/流结果一致性后者关注故障后免重放恢复。4.8 LLM 工具链Live AI声明“online ML, RAG pipelines, vector indexes... your ML pipeline works on fresh data.”代码落点python/pathway/xpacks/llm 模块承载 LLM 封装、解析器、嵌入器、切分器与内存向量索引等工具xpacks/connectors则承载相关连接器依赖落点xpack-llm分组见 2.2 节安装 OpenAI、LiteLLM、LangChain、LlamaIndex 等xpack-llm-docs安装 docling/unstructured/paddleocr 等文档解析栈xpack-llm-local支持本地推理sentence-transformers/transformers仓库内还包含面向 LLM 评测的集成测试目录 integration_tests/rag_evals可看到 RAG 评测管线的组织方式。4.9 连接器生态内置 40 原生连接器Airbyte 扩展至 350声明“comes with 350 connectors, including SharePoint. Or implement your own.”从源码结构看python/pathway/io 目录下包含40 个原生连接器子包覆盖消息队列/流kafka、kinesis、pulsar、nats、mqtt、redpanda、rabbitmq、pubsub、leann、logstash数据库/数据仓库postgres、mysql、mssql、mongodb、sqlite、clickhouse、questdb、duckdb、bigquery、dynamodb、elasticsearch文件与对象存储csv、jsonlines、plaintext、fs、s3、minio、gdrive、deltalake、iceberg、pyfilesystem向量库服务 RAGqdrant、milvus、weaviate、chroma、pinecone其他airbyte桥接数百种外部数据源、debeziumCDC、http、slack、python自定义连接器基础。“350”这一数字来自文档首页的表述主要经由 Airbyte 连接器扩展获得README 口径为“300”SharePoint 连接器属于需免费 license key 的高级连接器见 5 节。如果现有连接器不满足需求可基于pw.io.python自定义——这正是文档中“implement your own”的落点。4.10 其余特性的对应关系小结文档首页特性源码/配置证据Easy-to-use Python APIpython/pathway/init.py、udfs/stdlib模块Scalable Rust enginesrc/、pyproject.toml 的[tool.maturin]Stateful operationsgroupby/GroupedTable、stdlib/stateful、stdlib/temporalIncremental computationsexternal/differential-dataflow、external/timely-dataflowBatch and streaming alike70.streaming-and-static-modes.md、80.batch-processing.mdIn-memory processingREADME.md“pipeline is kept in memory”Easy to deploy (OpenTelemetry)pyproject.toml opentelemetry 依赖、set_monitoring_configExactly once consistencyREADME.mdfree: at-least-once / enterprise: exactly-oncePersistence and backfillingpython/pathway/persistence、src/persistenceLLM toolingpython/pathway/xpacks/llm、xpack-llm依赖组350 connectorspython/pathway/io40 个原生连接器 Airbyte 扩展五、许可证与 License Key软件许可证Pathway Live Data Framework 采用BSL 1.1许可见 LICENSE.txt 与 README.md允许无限非商业使用以及多数商业用途且免费仓库代码在 4 年后自动转为 Apache 2.0 开源许可Pathway 旗下的配套公共仓库示例、库、连接器则以 MIT 许可开源。License Key文档首页明确说明监控monitoring与部分高级连接器如 SharePoint等特性需要一个免费 license key通过 Pathway 官网注册即可获取。结合 Installation 文档企业版 license 可通过两种方式使用环境变量PATHWAY_LICENSE_KEYfile:///path/to/license.lic或内联 license 文件内容Python 代码中pw.set_license_key(file:///path/to/license.lic)后再调用pw.run()。更完整的许可说明可参考仓库内 Licensing Guide。六、下一步学习路径文档首页“Whats next”给出的学习路线在本仓库中均有对应文档建议按以下顺序阅读路径均为仓库相对路径Installation — 安装与依赖分组细节Pathway Overview — Live Data Framework 整体概览First realtime app — 第一个实时应用Core concepts — Table、Stream、时间戳等核心概念Why Pathway — 设计动机与取舍Streaming and Static Modes 与 Batch Processing — 两种运行模式Licensing Guide — 许可与 license key 细则。配套资源方面examples/notebooks 提供 45 个可交互 notebookexamples/projects 收录带 Dockerfile、CI 配置的完整示例工程integration_tests/ 覆盖 kafka、airbyte、s3、iceberg、gdrive、db_connectors 等方向的端到端集成测试Rust 引擎与 Differential/Timely Dataflow 内核源码分别位于 src/、external/differential-dataflow、external/timely-dataflow欢迎克隆仓库深入阅读并贡献代码。【免费下载链接】pathwayPython ETL framework for stream processing, real-time analytics, LLM pipelines, and RAG.项目地址: https://gitcode.com/GitHub_Trending/pa/pathway创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考