Prefect(2.4万星)2026:现代Python数据管线编排——Flow、Task与部署
Prefect(23,556星)是现代Python数据管线编排工具——动态Flow、任务重试、云或自托管调度。本文是完整指南。
💡 你将学到
Prefect(23,556星)是现代Python数据管线编排工具——动态Flow、任务重试、云或自托管调度。本文是完整指南。
直接给结论
prefecthq/prefect(23,556星,Python)是数据管线的编排工具。用 @flow 和 @task 装饰Python函数,Prefect就加上调度、重试、缓存和可观测性——带UI展示每次运行。可完全开源运行或使用Prefect Cloud。
核心概念
| 概念 | 是什么 |
|---|---|
| Flow | 顶层管线(装饰过的函数) |
| Task | Flow里的工作单元 |
| Deployment | 打包了调度的Flow |
| Work pool | Deployment运行的地方(本地、k8s、云) |
最小示例
from prefect import flow, task
@task(retries=2)
def fetch_data():
return [1, 2, 3]
@task
def process(data):
return sum(data)
@flow(name="etl-example")
def etl():
data = fetch_data()
return process(data)
if __name__ == "__main__":
etl()
pip install prefect
python etl.py
prefect server start # 打开UI http://localhost:4200
定时部署
prefect deployment build etl.py:etl -n daily
prefect deployment apply etl-deployment.yaml
prefect deployment run etl/daily
实用技巧
- 不稳定的API调用用
@task(retries=N),用cache_key_fn跳过没变化的工作。 - 用Prefect内置logger记录,运行历史可搜索。
- 先用本地server,规模化再迁移到work pools。
FAQ
免费吗? 是——Apache-2.0开源;Prefect Cloud提供托管。
和Airflow有什么区别? Prefect(23,556星)把管线当Python代码,DAG是动态的;Airflow(46,389星)用静态DAG文件。现代Python团队通常觉得Prefect更简单。
能跑在Kubernetes上吗? 能——work pools支持Kubernetes、Docker和无服务器runner。
相关文章
❓ 常见问题
Is it free?
Yes - Apache-2.0 open source; Prefect Cloud adds managed hosting.
How is it different from Airflow?
Prefect (23,556 stars) treats pipelines as Python code with dynamic DAGs; Airflow (46,389 stars) uses static DAG files. Prefect is often simpler for modern Python teams.
Can it run on Kubernetes?
Yes - work pools support Kubernetes, Docker, and serverless runners.
本站文章由编辑人工撰写,收录的工具均经过实测或公开资料核验。文中链接指向工具官网或 GitHub 仓库,仅作信息参考,不构成付费推广。
