/shub-workflow-toolkit:shub-workflow-issuersfrom shub-workflow-toolkit
Builds, fixes, and understands shub-workflow issuers — Scrapy Cloud data-pipeline components that read, process, deduplicate, and batch-output items. Covers IssuerScript subclasses, input types, stats keys, and migration from BaseDeliverScript.
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.
An issuer reads a massive input, processes the items, and writes a massive batch output —
chaining issuers builds the whole post-crawl data pipeline (consumer → filter → deduplicator →
balancer → delivery). IssuerScript
(shub_workflow/issuer/__init__.py)
is a BaseLoopScript (see the shub-workflow-scripts skill), generic over an IssuerItem subtype.
Full reference:
Appendix G: Issuer Classes.
Issuers are the modern backbone of the data chain; some older projects don't use them yet but are
expected to migrate, and delivery especially should move from the deprecated BaseDeliverScript to
an issuer.
| Class | Input | Use for |
|---|---|---|
IssuerScriptWithFileSystemInput[T] | batch files in a folder | mid-pipeline stages: consumer-of-files, filter, deduplicator, balancer, reducer (examples/file_input_issuer.py) |
IssuerScriptWithSCJobInput[T] | finished SC spider jobs (CLI target) | first stage reading raw crawl output, and delivery (examples/sc_job_input_issuer.py) |
Delivery-as-an-issuer (replacing BaseDeliverScript): examples/delivery_issuer.py.
API tables: references/api-cheatsheet.md.
IssuerScriptWithSCJobInput optionsIssuerScriptWithSCJobInput exposes three flags (defaults in parens) — all generic, not
delivery-specific:
set_item_source (True) — stamp each read item's source with the scanned spider's canonical
name. Set False when the scanned spider is a secondary/post-processing stage (it processes
data produced by a primary spider): its items already carry their originating source, so conserve
it instead of overwriting. This is why a delivery issuer keeps the upstream source.flush_on_each_input (False) — flush output files at the end of each scanned job. If you
want all items of one job in the same output file, pair it with a big default_filesize (so
a batch is never split by size before the per-job flush).scope_input_to_flow_id (False) — read only jobs tagged with this script's own FLOW_ID
(from --flow-id, or the FLOW_ID tag inside a workflow), so a script scheduled by a graph
manager reads all and only its own workflow instance's jobs. Ports what the deprecated
BaseDeliverScript did automatically; no-op (reads everything, with a warning) if no flow_id.Override the post_process_input_items(spider_job, args) hook (default no-op) to run logic once
per scanned job after all its items are read and before the flush (spider_job is the read
job — use its metadata/key/items). It enables the
accumulate-then-merge pattern below. It's also where you'd aggregate a job's stats if needed —
mix in SpiderStatsAggregatorMixin yourself and call self.aggregate_spider_stats(...) here (no
built-in flag for it).
get_new_inputs() visits the targeted spiders round-robin, rotating the starting spider across
loops: when the target matches multiple spiders (e.g. class:BaseSpider, to consume every source
in one job) a source with a big backlog can't starve the others, since only max_inputs_per_loop
inputs run per loop and each loop resumes where the previous left off. It's a no-op for a
single-spider target.
When an input's records must be combined into fewer output records (join, roll-up, reconcile),
override process_item to accumulate them (do not call super()), then in
post_process_input_items merge the accumulated records, set each combined record's id /
input_source, issue_item() them, and clear the accumulator; pair with flush_on_each_input=True
for one output file per job. This is generic to any IssuerScriptWithSCJobInput — a delivery
issuer may use it, but so may a filter or roll-up stage. See
examples/merge_issuer.py.
flush_on_each_input (decision guide)flush_on_each_input and post_process_input_items are orthogonal. flush_on_each_input only
controls output file granularity — one file per scanned job vs. size-batched by default_filesize
— it does not gate the hook. They co-occur in the one-delivery-file-per-job shape (issue the
job's records in the hook, then flush them together), which is why our delivery and per-job-merge cases
set True — but that pairing is not required:
flush_on_each_input=False. A roll-up/reducer
that accumulates a whole job and emits only a few merged records per job should leave it False, so
those records batch up to default_filesize; True would spray thousands of tiny one-record files.
The records issued in the hook are still written (by size / on_close), just packed across jobs.flush_on_each_input irrelevant (leave False). Non-issuing per-job side
effects — aggregate_spider_stats, pushing seeds to the frontier, capturing job metadata — touch no
output queue, so flush timing doesn't matter (e.g. a consumer that issues inline in process_item and
does its per-job seed push in the hook).Timing: the hook runs after any mid-read size-flushes (an inline issue_item that hit
default_filesize during the read loop already wrote a file) and before the per-job flush. So to
finalize a whole job's items before any of them are written, don't inline-issue — accumulate in
process_item (or use a big default_filesize) so nothing flushes before the hook.
Most issuers are one of two shapes that differ on dedup persistence:
parallel_outputs slots (so the same id always lands in the same slot). A discovery consumer
also explodes/side-effects — when each scraped record bundles many issuable objects, set
explode_input_items (a jmespath to that list) so the base calls process_item() once per object;
put per-item work in process_item and per-job side effects (e.g. extracting seeds and writing them to
the frontier) in post_process_input_items — no process_input override needed (see
examples/sc_job_input_issuer.py). Short-lived and cheaply
restartable — no load_last_outputs; a restart only loses in-memory dedup (the authoritative
dedup is downstream).load_last_outputs(...) on init to refill its bloom filter from the
last LOAD_DELIVERED_IDS_DAYS of its own (and downstream) output, so dedup survives restarts.
For a long history, set ids_cache_folder so the reload reads compact, merged ids files instead of
every output file (see ids_cache_folder in references/api-cheatsheet.md).So load_last_outputs / LOAD_DELIVERED_IDS_DAYS is a deduplicator trait (long-term
persistence), not a consumer one. Dedup lives in the deduplicators (not the consumer) deliberately:
the volatile, single-writer consumer stays cheap to restart, and dedup scales across N slots instead
of bottlenecking in one process.
It is also what the two archetypes' stats look like from outside: urls/seen/<source> is incremented
in the same branch as urls/issued/<source> (only for issued items), so a consumer reports
them equal, while a deduplicator reports a much bigger seen because load_last_outputs()
also counts every reloaded delivered id. Neither counts the items read. And urls/dupesrate/<source>
is a ratio (set, not incremented), so it must never be summed across jobs — to aggregate several
jobs of one source, sum urls/issued/<source> and derive the rate from the sums. And since every
stat is cumulative over the job's whole life, a long-running issuer cannot tell you when it did
something: for that, filter its timestamped Read <n> records from … / Wrote <n> records to … log
lines server-side — an input read with nothing written is 100% dupes, which no stat can distinguish
from "not reached yet". Full stat table and log-line cycle:
references/api-cheatsheet.md.
IssuerItem with your fields; bind it
(class X(IssuerScriptWithFileSystemInput[MyItem])).build_item_id(item) and set attributes.output_folder (required), default_filesize, and parallel_outputs (>1 for
hash-routed slots so N downstream issuers can each own a slot). Output is grouped per source by
default (one file per (slot, source)); set separate_output_by_source=False to pack all sources
into default_filesize-sized files per slot instead (one file per slot, no source in the default
filename). The output queue is an in-memory dict by default; set persist_items_queue_on_disk=True
to back it with an on-disk SqliteDict (much lower memory, slower) when items are large enough that
a batch would not fit in RAM — e.g. a delivery of records carrying heavy metadata.
persist_items_queue_dir chooses where that sqlite file goes (default: cwd), and
items_queue_read_chunk_size (default 100) caps how many items are held while writing the output
file. Never iterate a bucket with sqlitedict's own values()/items()/keys() — see the
footgun below.dedupe=True; for cross-run dedup set LOAD_DELIVERED_IDS_DAYS and call
load_last_outputs(...) in __init__.process_item (filter/transform — call super()); to combine an
input's records, accumulate in process_item and merge+issue_item in the
post_process_input_items hook (the accumulate-then-merge pattern).__main__ boilerplate (Script().run() — synchronous). Register in setup.py; deploy via the
scrapy-cloud-deployment skill.Projects often add a base issuer mixin (class ProjectIssuerMixin(ProjectScriptMixin, IssuerScript))
for shared output-routing/sizing — subclass it (mixin first) when present.
build_item_id. It's abstract and defines item identity/dedup. (In delivery issuers
that override process_item to accumulate, build_item_id may be unused — return a constant.)LOAD_DELIVERED_IDS_DAYS requires load_last_outputs() in __init__, or on_start() raises.
It's the deduplicator trait: it reloads the issuer's own (and optionally downstream) output
folders into seen so dedup survives restarts. A consumer omits it (in-memory dedup only).parallel_outputs hash-routes by id (hash_mod(id, N)) so the same id always lands in the
same slot — that's what lets N parallel downstream issuers each own one slot. Use input_slot to
pin an instance to one input slot.DeliverIssuerScript): a delivery is
an IssuerScriptWithSCJobInput you configure for the terminal stage. Which knobs you set is
use-case dependent, not fixed by "delivery": close_on_no_inputs=True and — for one file per job
— flush_on_each_input=True + a big default_filesize are typical; dedupe=False and
set_item_source=False apply only when the data was already deduplicated/post-processed upstream
(delivering a primary spider's crawl keeps the defaults). You supply build_item_id and the
destination (compute_destination_filename). Replaces the deprecated BaseDeliverScript (warns
on instantiation). Example: examples/delivery_issuer.py; migrating an
old one: references/migrating-from-basedeliverscript.md.get_project_running_spiders(crawlmanagers=self.source_crawlmanagers). The attribute defaults to
("py:crawlmanager.py",); set it to the actual py:<name>.py scripts that schedule the consumed
spiders, or a source whose manager is between jobs counts as stopped and gets flushed early.loop_mode for a continuous stage; use close_on_no_inputs=True for a run-to-completion
stage (e.g. reducers, delivery).Script().run()), and always super().add_argparser_options() if
you add CLI args.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())
MyIssuer().run()
examples/delivery_issuer.py (opens in a new tab)examples/file_input_issuer.py (opens in a new tab)examples/merge_issuer.py (opens in a new tab)examples/sc_job_input_issuer.py (opens in a new tab)references/api-cheatsheet.md (opens in a new tab)references/migrating-from-basedeliverscript.md (opens in a new tab)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