Skip to content

API Reference parrot_formdesigner.services.sinks.csv_file

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_formdesigner.services.sinks.csv_file

View source

CsvFileSink — lock-free single-line append to a local CSV file.

The Microsoft-Forms-style use case that motivated this feature: a survey whose responses land as one appended row in a local file, inside an allowlisted base directory.

Two decisions constrain this sink tightly (spec section 8, resolved):

  • No lock. One write emits exactly one \n-terminated line in a single write call. Concurrent workers can still interleave a long row; that is a documented, accepted limitation — never coordinate via a file lock.
  • .xlsx is out of scope. A workbook cannot be appended — it must be rewritten — which is irreconcilable with the above. This sink is CSV only.

Alias AbstractSubmissionSink

Re-exported from parrot_formdesigner.services.sinks.base.AbstractSubmissionSink.

Class CsvFileSink

One appended line per submission, inside an allowlisted base dir.

Capabilities are exactly {WRITE, PROVISION} — deliberately NOT EXTEND (an existing file's header is never rewritten) and NOT READ/LIST (write-only by declaration; the ABC's defaults raise SinkNotCapableError for those).

Parameter Type Default Description
target CsvFileTarget The validated :class:CsvFileTarget this sink writes to.
alias_registry SinkAliasRegistry Resolves target.connection to a base directory and contains target.path within it.
tenant str Tenant scope used to resolve the connection alias.

Attributes:

Attribute Type Description
capabilities frozenset[SinkCapability] Write-only: {WRITE, PROVISION}. No READ, no LIST, no EXTEND.

Method CsvFileSink.ensure_target

Create the file with a header row when absent.

When the file already exists, its header is left byte-identical — this sink deliberately does NOT declare EXTEND. If the form now produces columns the existing header lacks, a warning is logged (never a rewrite): those columns are cached as _extra_columns and their values are appended as TRAILING fields (beyond the existing header's column count) on every subsequent :meth:write.

ensure_target(form: FormSchema) -> None

Parameter Type Default Description
form FormSchema

Raises:

  • SinkUnavailableError — If the file cannot be created/read (permission error, missing/unwritable directory, etc.).

Method CsvFileSink.write

Append one row: exactly one fh.write() syscall.

Column order is the cached header from the most recent :meth:ensure_target call, plus any drifted "extra" columns as trailing fields. If ensure_target has never run, falls back to payload's own key order.

write(submission: FormSubmission, payload: Any) -> str

Parameter Type Default Description
submission FormSubmission The submission being persisted.
payload Any The flattened row dict for this submission.

Returns: str — The persisted submission_id.

Raises:

  • SinkUnavailableError — If the append fails.

Alias CsvFileTarget

Re-exported from parrot_formdesigner.core.persistence.CsvFileTarget.

Alias FormSchema

Re-exported from parrot_formdesigner.core.schema.FormSchema.

Alias FormSubmission

Re-exported from parrot_formdesigner.services.submissions.FormSubmission.

Alias SinkAliasRegistry

Re-exported from parrot_formdesigner.services.sink_aliases.SinkAliasRegistry.

Alias SinkCapability

Re-exported from parrot_formdesigner.core.persistence.SinkCapability.

Alias SinkUnavailableError

Re-exported from parrot_formdesigner.services.sinks.base.SinkUnavailableError.

Alias column_names_for

Re-exported from parrot_formdesigner.services.sinks.mapper.column_names_for.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally