Progress API
scinr.newton.progress.ProgressEvent
dataclass
One progress event emitted by :func:~scinr.newton.pipeline.run_pipeline.
Only the fields relevant to kind are set; every other field is None.
The event never carries the document itself nor any extracted content. Use
:meth:to_dict to serialize it (e.g. to JSON).
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
ProgressEventKind
|
What happened (see the "Event reference" table in the Progress Tracking guide). |
timestamp |
datetime
|
When the event was emitted (timezone-aware, UTC). |
job_id |
str | None
|
The |
tenant_id |
str | None
|
The document's tenant for document events, otherwise the
|
document_index |
int | None
|
Position of the document in the list of discovered documents;
unique within one |
doc_path |
str | None
|
Path of the document; stable for the whole life of the document. |
document_name |
str | None
|
Current document name — the name predicted from the file at
first, the real |
source_path |
str | None
|
File the document was discovered from, or |
stage |
str | None
|
Pipeline stage of a |
stages |
tuple[str, ...] | None
|
|
planned_stages |
tuple[str, ...] | None
|
|
total_documents |
int | None
|
|
duration_s |
float | None
|
Seconds spent in the stage / document / pipeline that just ended. |
metrics |
Mapping[str, int] | None
|
|
status |
DocumentStatus | None
|
|
stopped_at |
str | None
|
|
success |
bool | None
|
|
error |
str | None
|
|
scinr.newton.progress.ProgressCallback
Base class for synchronous progress callbacks.
Subclass it and override either :meth:on_event (one entry point for every
event) or only the on_<kind> methods you care about; every method is a
no-op by default.
Runs in a dedicated worker thread (one per run_pipeline() call), never on
the event loop, so it may block — call a blocking database client, requests,
etc. Events are delivered one at a time and in order, so within one
run_pipeline() call the callback never runs concurrently with itself. A
single instance shared by several concurrent run_pipeline() calls can
run concurrently with itself: do not assume thread-safety in that case.
Exceptions raised by a callback are logged (logger scinr.newton.progress)
and ignored; they never abort the ingestion.
on_document_finished
A document finished processing (status, stopped_at, error).
on_document_started
A document started processing (planned_stages).
on_documents_discovered
The documents to process are known (total_documents, stages).
on_event
Called for every event. By default dispatches to on_<event.kind>.
on_pipeline_completed
The run returned a PipelineResult (always the last event).
on_pipeline_failed
The run raised an exception (always the last event).
on_pipeline_started
The run started (always the first event).
on_stage_completed
A document (or the tabular batch) finished stage (metrics).
on_stage_failed
A document stopped at stage because of a failure (error).
scinr.newton.progress.AsyncProgressCallback
Base class for asynchronous progress callbacks.
Same contract as :class:ProgressCallback, but every method is a coroutine
awaited on the pipeline's own event loop — so it can use async clients bound to
that loop (motor, httpx, the async Neo4j driver, …). Events are delivered one at
a time and in order; within one run_pipeline() call the callback never runs
concurrently with itself (a shared instance across concurrent calls can).
A coroutine that blocks internally (requests, pymongo, time.sleep)
freezes the whole event loop — and with it the ingestion. Write blocking code as
a :class:ProgressCallback instead.
Exceptions raised by a callback are logged (logger scinr.newton.progress)
and ignored; they never abort the ingestion.
on_document_finished
async
A document finished processing (status, stopped_at, error).
on_document_started
async
A document started processing (planned_stages).
on_documents_discovered
async
The documents to process are known (total_documents, stages).
on_event
async
Called for every event. By default dispatches to on_<event.kind>.
on_pipeline_completed
async
The run returned a PipelineResult (always the last event).
on_pipeline_failed
async
The run raised an exception (always the last event).
on_pipeline_started
async
The run started (always the first event).
on_stage_completed
async
A document (or the tabular batch) finished stage (metrics).
on_stage_failed
async
A document stopped at stage because of a failure (error).
scinr.newton.progress.ProgressTracker
Built-in progress callback that keeps an aggregated, in-memory view of a run.
Pass it in run_pipeline(callbacks=[tracker]) and call :meth:snapshot at any
time — from the event loop or from another thread — to get a
:class:ProgressSnapshot. The tracker is updated synchronously as each event is
emitted (it does not go through the callback queue), so a snapshot is never
behind the pipeline.
The state lives only in the memory of the current process: it is not persisted
and is not visible from other processes. One instance is meant for one
run_pipeline() call; a second pipeline_started event resets it.
scinr.newton.progress.ProgressSnapshot
dataclass
Point-in-time view of a run, returned by :meth:ProgressTracker.snapshot.
Attributes:
| Name | Type | Description |
|---|---|---|
status |
Literal['pending', 'running', 'success', 'completed_with_errors', 'failed']
|
|
job_id |
str | None
|
The |
started_at |
datetime | None
|
When the run started (UTC), or |
finished_at |
datetime | None
|
When the run ended (UTC), or |
elapsed_s |
float
|
Seconds since the run started, up to |
stages |
tuple[str, ...]
|
Document stages that will run (empty until documents are discovered). |
total_documents |
int | None
|
Number of documents to process, or |
documents_pending |
int
|
Documents not started yet ( |
documents_running |
int
|
Documents in progress. |
documents_succeeded |
int
|
Documents finished with status |
documents_partial |
int
|
Documents finished with status |
documents_failed |
int
|
Documents finished with status |
documents_skipped |
int
|
Documents finished with status |
running_by_stage |
Mapping[str, int]
|
Number of documents currently in each stage. |
completed_by_stage |
Mapping[str, int]
|
Number of documents that completed each stage. |
failed_by_stage |
Mapping[str, int]
|
Number of documents that failed at each stage. |
tabular |
Literal['running', 'completed', 'completed_with_errors'] | None
|
State of the tabular batch: |
percent |
float
|
Overall document progress, 0-100, rounded to one decimal. The tabular batch does not count towards it. |
documents |
Mapping[int, DocumentProgress]
|
Progress of every started document, keyed by |
error |
str | None
|
Error message when the run raised, otherwise |
scinr.newton.progress.DocumentProgress
dataclass
Progress of one document, as seen by :class:ProgressTracker.
Attributes:
| Name | Type | Description |
|---|---|---|
document_index |
int
|
Position of the document among the discovered documents. |
doc_path |
str | None
|
Path of the document. |
document_name |
str | None
|
Latest known document name. |
tenant_id |
str | None
|
Tenant of the document ( |
status |
Literal['running', 'success', 'partial', 'failed', 'skipped']
|
|
current_stage |
str | None
|
Stage in progress right now, or |
planned_stages |
tuple[str, ...]
|
Stages this document will run. |
completed_stages |
tuple[str, ...]
|
Stages this document completed, in order. |
stopped_at |
str | None
|
Stage where the document stopped because of a failure, or |
error |
str | None
|
Error message when the document failed, or |
started_at |
datetime
|
When the document started (UTC). |
finished_at |
datetime | None
|
When the document finished (UTC), or |