/shub-workflow-toolkit:shub-workflow-scriptsfrom shub-workflow-toolkit
Guides writing Python scripts using shub_workflow base classes for Scrapy Cloud: scheduling spiders, querying jobs, aggregating stats, and running as crawl managers or monitors.
Ships in shub-workflow-toolkit. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
shub-workflow scripts subclass a base class in
shub_workflow/script.py
and get, for free: argument parsing (+ reusable -g/-v "programs"), project-id resolution, the
ScrapinghubClient, job scheduling with flow/name tagging, paginated+retrying job queries, a Scrapy
stats collector and an FSHelper. The deep reference is the wiki:
Appendix B: Script Classes.
A brand-new file isn't yet registered in the project's setup.py, so you can't tell from the repo.
When asked to "create a script", confirm with the user whether it will deploy to or operate on
Scrapy Cloud (run as an SC job, schedule spiders/scripts, scan/query SC jobs, aggregate stats,
etc.). If yes → use these base classes. If it's just a local utility with no SC interaction, a plain
script is fine and this skill doesn't apply. When editing an existing file that already imports
shub_workflow.script, this skill applies directly.
| Base class | Use when | Template |
|---|---|---|
BaseScript | one-shot: parse args, do work in run(), exit (the default) | examples/plain_script.py |
BaseLoopScript | must repeat work on an interval / run continuously until stopped | examples/loop_script.py |
BaseLoopScriptAsyncMixin (+ BaseLoopScript) | the loop cycle is asyncio-based (schedules/awaits many things at once) | examples/async_loop_script.py |
ArgumentParserScript | only argparse + PROGRAMS, no SC access (rare; the base the others build on) | — |
Projects usually add a shared base mixin (common CLI options/helpers) that every concrete script inherits — see examples/project_base_mixin.py. Check whether the project already has one and build on it rather than re-adding shared options.
description (property) and add your arguments in add_argparser_options() —
always call super() first so --project-id/-g/-v/etc. survive.run() for BaseScript; workflow_loop() (returns bool; async def for the async mixin) plus optional on_start()/on_close() for loop scripts.__main__ boilerplate (below).setup.py. Deployment itself is handled by the
scrapy-cloud-deployment skill, not here.super().add_argparser_options() before adding arguments, or you lose the framework
flags (--project-id, --flow-id, -g/-v, loop flags).class X(ProjectMixin, BaseScript) — mixin first, concrete base last. The mixin
must inherit the typing-only BaseScriptProtocol (never BaseScript), so the implementation
isn't duplicated in the MRO.BaseLoopScriptAsyncMixin script's run() is a coroutine —
launch it with asyncio.run(script.run()), and make workflow_loop an async def.self.project_id is the target (where you schedule/query, from
--project-id); the script's own running project can differ. Don't hardcode ids; pass
--project-id or set default_project_id.workflow_loop() returns bool: True keeps looping (with --loop-mode/loop_mode);
False stops immediately. A loop with loop_mode = 0 runs its body once.project_required = False only for scripts that genuinely never touch SC.self.fshelper (an FSHelper) — don't construct your own
FSHelper/S3Helper. To configure its credentials/role/ACLs, override the init_fshelper()
hook (default is a bare FSHelper()); self.project_settings is available there. See the
api-cheatsheet's File operations and the shub-workflow-fshelper skill.-g/-v PROGRAMS mechanism (predefined command-line shortcuts), see the
scanjobs-programs skill — scanjobs.py is the canonical example of a heavily
PROGRAMS-driven script.if __name__ == "__main__":
import logging
from shub_workflow.utils import get_kumo_loglevel
logging.basicConfig(format="%(asctime)s %(name)s [%(levelname)s]: %(message)s", level=get_kumo_loglevel())
script = MyScript()
script.run() # ... or asyncio.run(script.run()) for a BaseLoopScriptAsyncMixin script
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub scrapinghub/shub-workflow --plugin shub-workflow-toolkit10 skills in this plugin
/scanjobs-programsUse for help using shub_workflow's scanjobs tool — scanning ScrapyCloud jobs to extract and plot data from stats, logs, items, spider args or job metadata. Also reach for it, instead of a hand-rolled job-listing script, to take a census of a spider's jobs over a time window: how many ended with each close_reason (e.g. memusage_exceeded / killed by oom), on which deployed version, with which units, alongside per-job stats such as memusage/max. Covers building a scanjobs command line (the stat/log/item/spider-arg/meta patterns, the postscript post-processor -c, the --plot mini-language, time windows, and output modes) and the predefined "programs" shortcut: the PROGRAMS dict in a project's scripts/scanjobs.py (a subclass of shub_workflow.utils.scanjobs.ScanJobs), invoked as `scanjobs.py -g <program> -v key:val`, including {var} placeholders and {{ }} escaping. Applies to any project whose scripts/scanjobs.py subclasses shub_workflow's ScanJobs./shub-workflow-architecturesUse when a developer wants help designing (or redesigning) the architecture of a shub-workflow based Scrapy Cloud project — "help me design the architecture for this project", "how should I structure the crawl managers / consumers / delivery", "which components do I need", "how do I feed my spiders from a frontier", "how do I scale this crawl", "should I use a graph manager", or when migrating a project away from a central graph manager or from spiders that read/write the frontier (Frontera). Runs an INTERACTIVE design session: interviews the developer in short rounds to uncover the requirements they haven't stated yet, maps them to the independent-agents + role-separation architecture (or to a graph manager where a short ordered sequence fits), writes a design document with roles, storage contracts, scheduling and scale knobs, checks it against known pitfalls, and then scaffolds the script skeletons for the chosen roles. Covers seeds vs url frontiers, the post-crawl data chain, downloads, keep-alive scheduling, back-pressure and recrawling./shub-workflow-crawl-managersUse when building, updating, fixing, or understanding a shub-workflow crawl manager — a script that schedules spider jobs on Scrapy Cloud and reacts to their outcomes, built on shub_workflow.crawl (CrawlManager / PeriodicCrawlManager / GeneratorCrawlManager / AsyncSchedulerCrawlManagerMixin) and WorkFlowManager. Covers choosing the base class, the set_parameters_gen() generator pattern, the outcome/retry/throttling hooks, async concurrent scheduling, and the name/flow-id/loop-mode rules. Use for any crawl-manager script in any project that subclasses these classes (directly or via a project base mixin)./shub-workflow-diagramsUse when asked to build, update or restyle an architecture diagram for a shub-workflow based project — a workflow/pipeline diagram (the spiders, crawl managers, consumers, issuers, deduplicators, balancers, downloaders, delivery and the storages between them) or a class hierarchy / UML diagram of its script classes. Covers the house style shared by these projects (banded "swimlane" stages with a Role box, one warm palette, left-to-right flow), the plain-data model you write, the ready-made rendering engine to copy, and the Graphviz constraints that make the result stable instead of reshuffling on every run. Reach for it for "draw the workflow", "diagram the architecture", "update the workflow diagram", "class diagram of the scripts", or when a README's architecture PNG has gone stale./shub-workflow-fshelperUse when reading, writing, listing, copying, moving, or deleting files through shub-workflow's cloud-agnostic filesystem layer — the `shub_workflow.utils.futils` module and its `FSHelper` class (the recommended one; `S3Helper` is its deprecated backward-compatibility base) — i.e. any code that touches `s3://`, `gs://`, or local paths the same way, needs AWS role-assumed (STS) credentials, or must list/download deliveries in a bucket. Covers the prefix-based dispatch, module functions vs. the helper class, credential/role handling, the three listing variants (`list_folder` vs `list_path` vs recursive), `op_kwargs`/ACLs, and the install extras. Reach for it whenever you see `from shub_workflow.utils.futils import ...`, an `FSHelper`, or any project-local factory that returns one (a `build_fshelper()`-style wrapper, `self.fshelper`) — its API is NOT guessable and not discoverable by `dir()`, so check here before calling anything on it./shub-workflow-graph-managersUse when building, updating, fixing, or understanding a shub-workflow graph manager — a script that runs an arbitrary DAG of tasks (spiders and scripts, including crawl managers and deliver scripts) on Scrapy Cloud with dependencies, built on shub_workflow.graph (GraphManager + Task / SpiderTask) and WorkFlowManager. Covers configure_workflow(), Task vs SpiderTask, dependency linking (add_next_task / add_wait_for), the on_finish/retry routing, resources, parallelization, and the start directives. Use for any graph-manager / flow-manager script that subclasses GraphManager (directly or via a project base mixin).Other plugins' skills for the same job