将任何 Python 函数转变成一个可被观察和编排的流程

Python任务编排和工作流管理库之prefect使用详解 在数据工程和科学的世界中,任务编排和工作流管理变得越来越重要。随着数据处理任务的复杂性增加,开发人员需要一种可靠且易于使用的工具来设计、监控和管理这些任务。Prefect 是一个用于构建、监控和管理数据管道的 Python 库,它简化了工作流的创建和执行,同时提供了强大的错误处理和重试机制。本文将详细介绍 Prefect 库,包括其安装方法、主要特性、基本和高级功能,以及实际应用场景,帮助全面了解并掌握该库的使用。 阅读详情

Prefect 是一个用于数据密集型工作流程编排的工具。它能够最简单地将任何 Python 函数转变成一个可被观察和编排的工作单元。通过 Prefect 可以构建弹性的、动态的工作流程,使其能够对周围的环境做出反应,并能从意外变化中恢复过来。通过添加装饰器,Prefect 提供了自动重试、分布式执行、调度、缓存等诸多增强功能。每个任务都能被追踪,并可通过 Prefect 服务器或 Prefect Cloud 仪表板进行监控。

from prefect import flow, task   from typing import List   import httpx         @task(retries=3)   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!   github_stars(["PrefectHQ/Prefect"])   

运行一些流程后,打开 Prefect UI 查看:

prefect server start   

这是将任何 Python 函数转换为可观察和编排的工作单元的最简单方法。

快速入门

第 1 步:安装

pip install -U prefect   

第 2 步:连接 Prefect 的 API

注册永久免费的 Prefect Cloud 帐户,或者使用 Prefect Cloud 的部分功能托管个人服务器。

  1. 如果使用 Prefect Cloud,请使用现有帐户登录或在https://app.prefect.cloud/创建新帐户。

  2. 如果设置新帐户,请为帐户创建一个工作区。

  3. 使用prefect cloud login Prefect CLI 命令从你的环境登录 Prefect Cloud 。

prefect cloud login   

SkillFlow:基于流程驱动与递归技能进化的智能体编排范式 在人工智能领域,智能体(Agent)系统正从执行固定指令向自主决策与学习演进。其核心原理在于通过感知环境、规划决策与执行动作的循环,完成复杂任务。传统智能体编排常面临流程僵化、容错性差与经验难以复用等技术挑战。为解决这些问题,一种融合了流程驱动与递归进化思想的技术范式应运而生,它通过动态管理执行状态(Flow State)和自动化封装成功模式为可复用技能(Skill),赋予系统在运行中自我优化的能力。这种范式尤其适用于自动化工作流、复杂问题拆解与动态环境适应等应用场景,其核心价值在于构建更具韧性与自适应性的 阅读详情

相关推荐

DeepSeek Harness实战:从API调用到任务编排的工程化部署全流程

在大模型应用开发中,API调用与任务编排是提升效率的关键。DeepSeek Harness作为模型访问与任务编排框架,将CLI、Web界面、桌面端统一在可复用链路中,支持批量测试、模板渲染与插件扩展。其底层原理在于通过模型访问层屏蔽上游差异,任务编排层管理并行/顺序执行,插件机制提供扩展点。技术上,本地部署需Node.js与pnpm环境,启动后可通过HTTP接口集成到现有系统。适用于AI应用团队进行批量评测、提示词资产积累或团队共享入口。本文以实践视角梳理环境准备、功能验证、接口调用与常见问题排查,帮助开发

weixin_33843409的博客 516

Python如何编排AI智能体:从控制流到工具调用的完整实战

在AI应用开发中,Python不仅是数据分析与机器学习的主流语言,更是构建AI智能体的关键底座。智能体的核心并非单一的大模型,而是围绕模型意图设计的一套编排流程:通过控制流、数据流与工具调用的组合,让模型在合适节点做决策,代码负责执行具体动作。ReAct模式正是这种编排思想的典型落地,它让模型交替进行推理与行动,在真实环境中逐步完成任务。借助Python丰富的第三方库与装饰器机制,开发者可以用轻量代码实现类似LangChain的智能体工作流,并灵活管理上下文窗口、API Key与并发任务。从自动化拉取数据库

weixin_29053383的博客 271

PenguinHarness:用代码生成与编排打造可控的 AI Agent

随着大模型能力的提升,AI Agent 成为实现复杂任务自动化的关键,但开发门槛高、调试困难、上下文管理复杂等问题依然突出。借助代码生成与运行时编排相结合的方式,开发者可以用自然语言描述业务目标,由系统自动生成结构化的 Agent 定义,实现流程编排、工具调用与上下文策略的标准化管理。这种方案不仅显著提升开发效率,还让生成结果具备可读性、可维护性与复用性,在财报解读、技术周报等真实场景中展现出工程落地价值。PenguinHarness 正是这一思路的开源实践,通过生成层、编排层与执行层的分层设计,以及工具注

weixin_34216107的博客 442

deer-flow实战:用JSON DSL构建低代码可视化流程编排引擎

在微服务与中后台系统中,业务流程往往散落在状态机、定时任务和if-else中,导致逻辑难以维护和追踪。低代码流程编排正是为解决这类问题而生:通过将流程抽象为有向图,以节点和连线的形式定义执行路径,并采用JSON DSL作为机器可读的流程契约。这一设计让开发者无需编写繁琐的业务代码,即可通过可视化设计器拖拽节点、配置分支、接入HTTP调用与人工审批,实现从普通状态流转到复杂业务编排的快速落地。deer-flow作为一款轻量级开源工作流引擎,完整覆盖了流程定义、运行时实例管理、审批回调、前端设计器对接等生产级能

weixin_34178244的博客 164

Python爬虫-使用Prefect框架实现一个可视化爬虫项目

本文是该专栏的第19篇,后面会持续分享python爬虫干货知识。相信有的同学,在处理爬虫项目的时候,有时也会需要你将爬虫项目进行一个可视化展示,方便管理者能及时详细的了解当前爬虫任务的执行进度以及执行情况,甚至需要做一个爬虫监控预警的可视化任务。而本文,笔者将结合一个实际爬虫案例,借助于Prefect 框架,来实现爬虫项目的可视化。Prefect,它是一个开源的工作流自动化框架,专为数据科学和机器学习工作流而设计。它允许用户定义、调度、执行和监控复杂的计算任务,并确保这些任务按照指定的依赖关系和顺序执行。

Python进阶专栏《爬虫实战进阶》,《Pyppeteer从入门到精通》原创作者 948

Prefect基本用法:编程实现工作流程

本文介绍了Prefect的基本用法,包括定义任务、创建工作流程、调度和执行工作流程,以及任务状态和错误处理。Prefect提供了灵活而强大的工具,用于管理复杂的工作流程,并提供了丰富的功能和扩展性来满足各种需求。工作流程是任务的有向无环图(DAG),其中每个节点都是一个任务。定义好工作流程后,我们可以使用Prefect的执行引擎来调度和执行工作流程。Prefect提供了丰富的任务状态和错误处理机制,用于监控和处理任务的执行结果。执行引擎将根据任务之间的依赖关系自动调度任务的执行,并按照正确的顺序执行它们。

TechRoar的博客 828

开题报告该怎么写

考研即将来临,而一般很多大学都会选择在考研结束之后开始安排选题和开题报考(考研之前一般都不谈,老师也很人性化的,不愿意耽误你的复习) 但无论怎么推迟,我们最终都需要去面对并完成这些任务。 现在我就要教大家该如何写一个完整的开题报告! 准备模板。不同的学校有不同的格式,一般情况你的导师会给你们一个学校的标准格式,这个不用太费心。有了模板我们就可以按照模板的“线索”一步一步填充完成即可! 一般大致格式可谓: 研究背景/论文的目的、背景和意义 我们需要写明选择该题目的...

wuyueweifeng的博客 1097

Unity详细介绍说明限制Unity帧率的方式

在Unity开发中,帧率(FPS,Frames per Second)是一个非常重要的表现标准,它直接影响了游戏运行的流畅度。在某些应用场景里,我们可能需要手动限制帧率。限制帧率可以减少电脑的CPU和GPU负载,使运行更加稳定,同时对于移动设备来说还能有效降低电量消耗。下面就详细介绍几种限制Unity中帧率的方式。

zjw1349547081的专栏 5437

AI智能体赋能Cypress:自动化前端测试的新范式

自动化测试是现代软件工程保障质量的核心实践,其原理是通过脚本模拟用户操作,对软件功能进行验证。随着大语言模型(LLM)和智能体(Agent)技术的发展,测试自动化正迈向智能化新阶段。智能体能够理解自然语言描述的测试需求,并自主规划、执行测试步骤,这为应对前端UI频繁变更、测试用例维护成本高等挑战提供了新思路。在工程实践中,将Cypress这一流行的前端测试框架封装为智能体可调用的标准化技能(Skill),是实现这一愿景的关键。通过设计清晰的交互协议和状态管理机制,智能体可以像人类测试工程师一样“感知”页面状

weixin_33726318的博客 687

【HCIE】FRR+BFD+OSPF与BGP联动

FRR+BFD+OSPF与BGP联动

Wenrs的博客 1997

OpenFOAM-多孔介质模型(porous media)

文章目录一、多孔介质(porous media)二、使用步骤1.达西定律2.Darcy-Forchheimer3.OpenFOAM fvOptions4.paraview动画每帧显示时间(Annotate Time)5.参考内容总结 一、多孔介质(porous media) 在流体力学中,流体流经多孔介质是指流体流经多孔介质时的行为方式,如海绵或木材,或使用沙子或其他多孔材料过滤水。 我们将展示如何设置多孔层,并使用OpenFOAM模拟流体通过该介质。 二、使用步骤 1.达西定律 达西定律最初是由达西通.

zq93538196的博客 9939

【华为OD机试】贪吃蛇(python, java, c++, js)

贪吃蛇是一个经典游戏,蛇的身体由若干方格连接而成,身体随蛇头移动。蛇头触碰到食物时,蛇的长度会增加一格。蛇头和身体的任一方格或者游戏版图边界碰撞时,游戏结束。 下面让我们来完成贪吃蛇游戏的模拟。 给定一个NM的数组arr,代表NM个方格组成的版图,贪吃蛇每次移动一个方格。 若arr[i][j] == H,表示该方格为贪吃蛇的起始位置; 若arr[i][j] == F,表示该方格为食物, 若arr[i][j] == E,表示该方格为空格。 贪吃蛇初始长度为1,初始移动方向为向左。

A_D_I_D_A_S的博客 542

AUTOSAR进阶图解==>AUTOSAR_SWS_ECUStateManager

AUTOSAR ECU State Manager 摘要 AUTOSAR ECU状态管理器(EcuM)是Classic Platform 4.4.0规范中的核心模块,负责管理ECU的整个生命周期,包括启动、运行、关机和睡眠等状态转换。EcuM通过协调各基础软件模块的初始化过程,确保系统可靠运行。 主要功能包括: 启动管理 - 控制从硬件初始化到应用运行的完整启动序列 状态转换 - 管理RUN/POST_RUN/SHUTDOWN等状态切换 唤醒验证 - 区分真实与虚假唤醒事件 关机序列 - 确保安全关机保存关

一名留德华的,康德的信徒的,专注于汽车电子领域的博客 2477

【python三维深度学习】python三维点云从基础到深度学习

从三维点云基础知识到深度学习,将按照以下目录持续进行更新。更新完成的部分可以在三维点云专栏中查看。含数据与python源码。

叶子的博客 2万+

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: Python竟然这样处理文件?
下一篇: 基于Python的CAD二次开发:自动绘制脚手架(一)
Python_P叔
博客等级 码龄3年 5454粉丝 827原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值