# Writer

## timenet.writer

Serialization of a :class:`~timenet.dataset.TimeFDataset` to the TimeF on-disk format.

### ProgressStage

Bases: `StrEnum`

The writer's incremental stages. Only stages that carry information are emitted.

#### COMMIT `class-attribute` `instance-attribute`

```
COMMIT = 'commit'
```

#### SHARD\_FINALIZED `class-attribute` `instance-attribute`

```
SHARD_FINALIZED = 'shard_finalized'
```

#### TIME\_SERIES `class-attribute` `instance-attribute`

```
TIME_SERIES = 'time_series'
```

### TimeFWriter

Context manager that serializes a dataset into the TimeF format and commits it atomically.

#### abort

```
abort() -> None
```

Delete the staging directory. Safe to call more than once.

#### close

```
close() -> None
```

Write the manifest and atomically publish the staging directory.

Raises:

| Type | Description |
| --- | --- |
| `RuntimeError` | If :meth:`write` has not run successfully. |

#### write

```
write() -> None
```

Serialize every artifact except the manifest into the staging directory.

Raises:

| Type | Description |
| --- | --- |
| `TimeFValidationError` | If the schema was not derived, a shared annotation id is not field-equal across samples, or a series array violates the per-series contract. |

### WriteProgressEvent `dataclass`

A single progress event passed to the writer's `progress_cb`.

#### completed `instance-attribute`

```
completed: int
```

Number of items finished in this stage so far.

#### message `class-attribute` `instance-attribute`

```
message: str | None = None
```

Optional human-readable detail for the event.

#### stage `instance-attribute`

```
stage: ProgressStage
```

The writer stage this event reports.

#### total `instance-attribute`

```
total: int | None
```

Total number of items to process, or `None` if unknown.
