PrefectHQ / prefect

PrefectHQ / prefect

Prefect is a workflow orchestration framework for building data pipelines in Python. It’s the simplest way to elevate a script into a production workflow. With Prefect, you can build resilient, dynamic data pipelines that react to the world around them and recover from unexpected changes.

Prefect 是一个用于在 Python 中构建数据流水线的工作流编排框架。它是将脚本升级为生产级工作流的最简单方式。通过 Prefect,你可以构建具有弹性、动态的数据流水线,使其能够响应外部环境并从意外变化中恢复。

With just a few lines of code, data teams can confidently automate any data process with features such as scheduling, caching, retries, and event-based automations. Workflow activity is tracked and can be monitored with a self-hosted Prefect server instance or managed Prefect Cloud dashboard.

只需几行代码,数据团队就可以利用调度、缓存、重试和基于事件的自动化等功能,自信地自动化任何数据处理流程。工作流活动会被记录下来,并可以通过自托管的 Prefect 服务器实例或托管的 Prefect Cloud 仪表板进行监控。

Tip: Prefect flows can handle retries, dependencies, and even complex branching logic. Check our docs or see the example below to learn more!

提示: Prefect 工作流可以处理重试、依赖关系,甚至是复杂的分支逻辑。请查看我们的文档或参考下方的示例以了解更多信息!

Getting started

入门指南

Prefect requires Python 3.10+. To install the latest version of Prefect, run one of the following commands: pip install -U prefect uv add prefect

Prefect 需要 Python 3.10+ 环境。要安装最新版本的 Prefect,请运行以下命令之一: pip install -U prefect uv add prefect

Then create and run a Python file that uses Prefect flow and task decorators to orchestrate and observe your workflow - in this case, a simple script that fetches the number of GitHub stars from a repository:

接着,创建一个 Python 文件并运行,利用 Prefect 的 flow 和 task 装饰器来编排和观察你的工作流。以下是一个简单的脚本示例,用于获取 GitHub 仓库的星标数量:

from prefect import flow, task
import httpx

@task(log_prints=True)
def get_stars(repo: str):
    url = f"https://api.github.com/repos/{repo}"
    count = httpx.get(url).json()["stargazers_count"]
    print(f"{repo} has {count} stars!")

@flow(name="GitHub Stars")
def github_stars(repos: list[str]):
    for repo in repos:
        get_stars(repo)

# run the flow!
if __name__ == "__main__":
    github_stars(["PrefectHQ/prefect"])

Fire up a Prefect server and open the UI at http://localhost:4200 to see what happened: prefect server start

启动 Prefect 服务器并打开 http://localhost:4200 的 UI 界面,即可查看运行情况: prefect server start

To run your workflow on a schedule, turn it into a deployment and schedule it to run every minute by changing the last line of your script to the following:

若要按计划运行工作流,可以将其转换为部署(deployment),并通过修改脚本的最后一行将其设置为每分钟运行一次:

if __name__ == "__main__":
    github_stars.serve(
        name="first-deployment",
        cron="* * * * *",
        parameters={"repos": ["PrefectHQ/prefect"]}
    )

You now have a process running locally that is looking for scheduled deployments! Additionally you can run your workflow manually from the UI or CLI. You can even run deployments in response to events.

现在,你本地运行的进程已经在监听计划中的部署任务了!此外,你还可以通过 UI 或命令行手动运行工作流,甚至可以根据事件触发部署。

Tip: Where to go next - check out our documentation to learn more about:

  • Deploying flows to production environments
  • Adding error handling and retries
  • Integrating with your existing tools
  • Setting up team collaboration features

提示: 接下来可以做什么——查看我们的文档以了解更多关于以下内容的信息:

  • 将工作流部署到生产环境
  • 添加错误处理和重试机制
  • 与现有工具集成
  • 设置团队协作功能

Prefect Cloud

Prefect Cloud

Prefect Cloud provides workflow orchestration for the modern data enterprise. By automating over 200 million data tasks monthly, Prefect empowers diverse organizations — from Fortune 50 leaders such as Progressive Insurance to innovative disruptors such as Cash App — to increase engineering productivity, reduce pipeline errors, and cut data workflow compute costs. Read more about Prefect Cloud here or sign up to try it for yourself.

Prefect Cloud 为现代数据企业提供工作流编排服务。通过每月自动化超过 2 亿个数据任务,Prefect 助力各类组织(从 Progressive Insurance 等财富 50 强企业到 Cash App 等创新颠覆者)提高工程生产力、减少流水线错误并降低数据工作流的计算成本。点击此处阅读更多关于 Prefect Cloud 的信息,或注册试用。

prefect-client

prefect-client

If your use case is geared towards communicating with Prefect Cloud or a remote Prefect server, check out our prefect-client. It is a lighter-weight option for accessing client-side functionality in the Prefect SDK and is ideal for use in ephemeral execution environments.

如果你的使用场景主要是与 Prefect Cloud 或远程 Prefect 服务器进行通信,请查看我们的 prefect-client。它是访问 Prefect SDK 客户端功能的轻量级选择,非常适合在临时执行环境中使用。

Connect & Contribute

连接与贡献

Join a thriving community of over 25,000 practitioners who solve data challenges with Prefect. Prefect’s community is built on collaboration, technical innovation, and continuous improvement.

加入由超过 25,000 名从业者组成的繁荣社区,与他们一起使用 Prefect 解决数据挑战。Prefect 社区建立在协作、技术创新和持续改进的基础之上。

Community Resources

  • 🌐 Explore the Documentation - Comprehensive guides and API references
  • 💬 Join the Slack Community - Connect with thousands of practitioners
  • 🤝 Contribute to Prefect - Help shape the future of the project
  • 🔌 Support or create a new Prefect integration - Extend Prefect’s capabilities
  • 📋 Tail the Dev Log - Prefect’s open source development blog

社区资源

  • 🌐 探索文档 - 全面的指南和 API 参考
  • 💬 加入 Slack 社区 - 与数千名从业者交流
  • 🤝 为 Prefect 做贡献 - 共同塑造项目的未来
  • 🔌 支持或创建新的 Prefect 集成 - 扩展 Prefect 的功能
  • 📋 关注开发日志 - Prefect 的开源开发博客

Stay Informed

  • 📥 Subscribe to our Newsletter - Get the latest Prefect news and updates
  • 📣 X and Bluesky - Latest updates and announcements
  • 📺 YouTube - Video tutorials and webinars
  • 📱 LinkedIn - Professional networking and company news

保持关注

  • 📥 订阅我们的通讯 - 获取最新的 Prefect 新闻和更新
  • 📣 X 和 Bluesky - 最新动态和公告
  • 📺 YouTube - 视频教程和网络研讨会
  • 📱 LinkedIn - 专业社交和公司新闻

Your contributions, questions, and ideas make Prefect better every day. Whether you’re reporting bugs, suggesting features, or improving documentation, your input is invaluable to the Prefect community.

你的贡献、提问和想法让 Prefect 每天都在进步。无论你是报告 Bug、建议新功能还是改进文档,你的投入对 Prefect 社区来说都弥足珍贵。