Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

prefect

БесплатноБез исполняемых скриптовНе проверен

Prefect is a Python workflow orchestration framework that turns functions into observable, retryable, schedulable data pipelines. Use when asked to…

TerminalSkillsот TerminalSkills★ 221 звезда на GitHub

Об этом скилле

Prefect

Overview

Prefect 3 turns Python functions into flows (@flow) made of tasks (@task), with retries, caching, logging, a UI and scheduled deployments. Two ways to run on a schedule: flow.serve(...) starts one long-running process that executes runs itself, and work pools plus workers (prefect deploy and prefect worker start) execute runs in managed infrastructure. Agents and prefect.deployments.Deployment from Prefect 2 are removed: importing Deployment raises an error.

Instructions

Install and run a server

python3 -m venv .venv && source .venv/bin/activate
pip install prefect httpx            # needs Python 3.11 or newer
prefect version

prefect server start                 # UI and API at http://127.0.0.1:4200
# In another shell, point clients at it:
prefect config set PREFECT_API_URL=http://127.0.0.1:4200/api

Running a flow without any server also works: Prefect starts a temporary local server for the run. For Prefect Cloud use prefect cloud login.

Flows and tasks

# flows/orders_etl.py
from datetime import timedelta
import httpx
from prefect import flow, task, get_run_logger
from prefect.cache_policies import INPUTS
from prefect.tasks import exponential_backoff

@task(retries=3, retry_delay_seconds=exponential_backoff(backoff_factor=10),
      retry_jitter_factor=0.5, timeout_seconds=120)
def fetch_orders(day: str) -> list[dict]:
    r = httpx.get("https://api.northwind-shop.dev/orders", params={"date": day}, timeout=30)
    r.raise_for_status()
    return r.json()["results"]

@task(cache_policy=INPUTS, cache_expiration=timedelta(hours=1))
def to_cents(order: dict) -> dict:
    return {"id": order["id"], "cents": round(order["amount"] * 100)}

@task
def load(rows: list[dict]) -> int:
    get_run_logger().info("loading %d rows", len(rows))
    return len(rows)

@flow(name="orders-etl", log_prints=True)
def orders_etl(day: str = "2026-10-23") -> int:
    orders = fetch_orders(day)
    rows = [f.result() for f in to_cents.map(orders)]   # runs the tasks concurrently
    count = load(rows)
    print(f"loaded {count} rows")
    return count

if __name__ == "__main__":
    orders_etl()

Key points: retry_delay_seconds takes a number, a list (one delay per retry) or exponential_backoff(...). Caching is configured with cache_policy (INPUTS, TASK_SOURCE, DEFAULT, from prefect.cache_policies); the old task_input_hash import is deprecated. task.submit(...) and task.map(...) return futures; call .result() or wait(futures) from prefect.futures. Tasks and flows may be async def; use await or asyncio.gather inside an async flow.

Schedule with flow.serve

Simplest deployment: one Python process that stays running and executes scheduled and manual runs.

# flows/daily_report.py
from prefect import flow

@flow(log_prints=True)
def daily_report(region: str = "emea"):
    print(f"report for {region}")

if __name__ == "__main__":
    daily_report.serve(name="daily-report", cron="0 8 * * *",
                       tags=["reporting"], parameters={"region": "emea"})

Run python flows/daily_report.py (keep it alive with systemd or a container), then trigger a run manually:

prefect deployment run "daily-report/daily-report" --param region=apac --watch
prefect deployment ls

serve also accepts interval (seconds or timedelta), rrule, schedules, paused and limit (concurrent runs).

Work pools, workers and prefect deploy

Use this when runs must execute on separate infrastructure (Docker, Kubernetes, cloud).

prefect work-pool create etl-process --type process
prefect deploy flows/orders_etl.py:orders_etl --name etl-prod --pool etl-process --cron "*/30 * * * *"
prefect worker start --pool etl-process
prefect deployment run "orders-etl/etl-prod" --param day=2026-10-22

prefect deploy also accepts --interval, --tag, --param and --job-variable, and can save the deployment definition to prefect.yaml (prefect init creates one); without that file it deploys straight from the command-line options. There is no default pool called default-agent-pool: create a pool first. Workers need access to the flow's source code, so use a shared path, a Git source (flow.from_source(...).deploy(...) in Python) or a built image. Read logs with prefect flow-run logs <id> and list runs with prefect flow-run ls.

Secrets, variables and failure alerts

# flows/with_config.py
from prefect import flow
from prefect.blocks.system import Secret
from prefect.blocks.notifications import SlackWebhook
from prefect.variables import Variable

def alert_slack(flow, flow_run, state):
    SlackWebhook.load("ops-alerts").notify(f"Flow {flow.name} run {flow_run.name} ended {state.type.value}")

@flow(on_failure=[alert_slack])
def sync_stripe():
    api_key = Secret.load("stripe-api-key").get()
    batch_size = Variable.get("stripe_batch_size", default="500")
    ...

Cr

Полный SKILL.md на GitHub

Установить prefect в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

_scores.json

FAQ

Что делает скилл prefect?

Prefect is a Python workflow orchestration framework that turns functions into observable, retryable, schedulable data pipelines. Use when asked to "orchestrate a Python pipeline", "schedule a flow with cron", "add retries and caching to tasks", "deploy a Prefect flow", "run a worker" or "alert when a flow fails". Covers Prefect 3.x flows and tasks, cache policies, flow.serve, work pools with workers, the prefect deploy CLI, blocks, variables and failure hooks.

Как установить скилл prefect?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл prefect запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить prefect с