Akka.Streams.Csv
1.5.74
Prefix Reserved
dotnet add package Akka.Streams.Csv --version 1.5.74
NuGet\Install-Package Akka.Streams.Csv -Version 1.5.74
<PackageReference Include="Akka.Streams.Csv" Version="1.5.74" />
<PackageVersion Include="Akka.Streams.Csv" Version="1.5.74" />
<PackageReference Include="Akka.Streams.Csv" />
paket add Akka.Streams.Csv --version 1.5.74
#r "nuget: Akka.Streams.Csv, 1.5.74"
#:package Akka.Streams.Csv@1.5.74
#addin nuget:?package=Akka.Streams.Csv&version=1.5.74
#tool nuget:?package=Akka.Streams.Csv&version=1.5.74
Akka.Streams.Csv
CSV parsing, formatting and header-to-dictionary flows for Akka.NET Streams. The package targets .NET Standard 2.0 and .NET 6. It processes stream elements in the application process; no broker, Aspire host or container is required.
dotnet add package Akka.Streams.Csv
Write CSV
CsvFormatting.Format accepts ImmutableList<string> rows and emits ByteString chunks. By default it uses UTF-8, comma delimiters, double quotes, backslash escaping, CRLF line endings and CsvQuotingStyle.Required. A field is quoted when needed for delimiters, quotes, escapes or embedded newlines; Always quotes every non-null field. Quotes and escape characters are doubled when formatting quoted fields. No byte-order mark is added unless supplied explicitly.
This complete example writes a header and two rows. Set CSV_OUTPUT to an output path or use example.csv in the working directory. It uses FileMode.Create, so an existing file at that path is overwritten.
using System.Collections.Immutable;
using Akka.Actor;
using Akka.IO;
using Akka.Streams;
using Akka.Streams.Csv.Dsl;
using Akka.Streams.Dsl;
var path = Environment.GetEnvironmentVariable("CSV_OUTPUT") ?? "example.csv";
var system = ActorSystem.Create("csv-writer", "akka.loglevel = WARNING");
try
{
var rows = new[]
{
ImmutableList.Create("name", "note"),
ImmutableList.Create("café", "comma, quote \" and newline\ninside"),
ImmutableList.Create("last", "plain")
};
var result = await Source.From(rows)
.Via(CsvFormatting.Format(byteOrderMark: ByteOrderMark.UTF8))
.RunWith(FileIO.ToFile(new FileInfo(path), FileMode.Create), system.Materializer());
if (!result.WasSuccessful) throw result.Error;
Console.WriteLine($"Wrote {result.Count} bytes to {path}");
}
finally { await system.Terminate(); }
A configured BOM is emitted as its own initial chunk, including for an empty upstream. Each row is formatted independently. Empty rows produce the configured line ending; null fields become empty columns. The current empty-row fast path encodes its line ending with UTF-8 even when a different encoding is selected, so use UTF-8 for consistent empty/nonempty output. Non-UTF-8 output and its chosen BOM are not necessarily supported by this package's byte-oriented parser.
Read CSV into dictionaries
CsvParsing.LineScanner accepts arbitrary ByteString chunks and emits ImmutableList<ByteString> rows. CsvToDictionary.ToDictionary consumes the first row as header names, then emits Dictionary<string, ByteString> values for later rows. Header text uses UTF-8 unless an encoding is supplied; field values remain bytes until decoded by the application.
Run this example against the file above, or set CSV_INPUT to a compatible CSV file with name and note headers.
using System.Collections.Generic;
using System.Text;
using Akka.Actor;
using Akka.IO;
using Akka.Streams;
using Akka.Streams.Csv.Dsl;
using Akka.Streams.Dsl;
var path = Environment.GetEnvironmentVariable("CSV_INPUT") ?? "example.csv";
var system = ActorSystem.Create("csv-reader", "akka.loglevel = WARNING");
try
{
var (read, completion) = FileIO.FromFile(new FileInfo(path))
.Via(CsvParsing.LineScanner())
.Via(CsvToDictionary.ToDictionary())
.ToMaterialized(Sink.ForEach<Dictionary<string, ByteString>>(row =>
Console.WriteLine($"{row["name"].ToString(Encoding.UTF8)}: {row["note"].ToString(Encoding.UTF8)}")), Keep.Both)
.Run(system.Materializer());
await completion;
var result = await read;
if (!result.WasSuccessful) throw result.Error;
}
finally { await system.Terminate(); }
All three CSV DSL flows materialize NotUsed; the examples retain completion from their file or terminal sink. Cancellation propagates to upstream. The flows create per-materialization parsing/header state and do not own a separate external client.
Parsing rules and limits
Parsing defaults to comma, double quote and backslash; delimiters and quote/escape characters are single bytes. LF, CR and CRLF terminate records outside quotes. Quoted fields can contain those bytes as data. CRLF remains one terminator when split between chunks; ordinary blank records remain a single empty field. A UTF-8 BOM at the start is consumed. Recognized UTF-16/UTF-32 BOMs throw UnsupportedCharsetException; Unicode U+2028 remains field data rather than a record separator.
Split escape sequences wait for their following byte in the streaming flow. Invalid escapes and dangling escapes at stream EOF fail with MalformedCsvException. A final unquoted row without a newline is emitted at EOF. Malformed-quote handling is not universally strict: an unterminated quoted final record can be left un-emitted without a failure. Validate input separately if every malformed record must be rejected.
The parser buffers incomplete rows and has no public maximum record/field length setting. Backpressure controls emitted rows but does not bound memory for a single arbitrarily long incomplete record. Field bytes are not a UTF-8 validation guarantee. No schema validation, typed conversion, checkpointing or recovery after a parse error is provided.
CsvToDictionary.WithHeaders(ImmutableList<string>) uses supplied headers and treats every incoming row as data. Header/data length differences use only the shared prefix: excess data is discarded and missing columns are omitted. Duplicate header names that collide in a row fail with the dictionary's ArgumentException; header-only input emits no dictionary. Choose a separate validation stage for strict column counts or schemas.
The low-level public CsvParser and CsvFormatter helpers are retained for compatibility; prefer the DSL for streaming. The public three-argument CsvParser retains its immediate incomplete-escape validation when Poll(true) is called directly. Only the streaming stage opts into waiting for a subsequent chunk; Poll(false) still rejects dangling escapes.
Tests
From the repository root, run either retained test target:
dotnet test src/Csv/Akka.Streams.Csv.Tests/Akka.Streams.Csv.Tests.csproj -c Release --framework net10.0
# On Windows with .NET Framework 4.8:
dotnet test src/Csv/Akka.Streams.Csv.Tests/Akka.Streams.Csv.Tests.csproj -c Release --framework net48
Tests retain parser/formatter/dictionary assertions and real CSV fixtures. Additional streaming cases cover UTF-8/BOM/quote boundaries, split CRLF and escapes, invalid escapes/EOF errors, standalone CR, preserved blank records, final demand/completion and cancellation. They require no Docker or cloud credentials.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Akka.Streams (>= 1.5.74)
-
net6.0
- Akka.Streams (>= 1.5.74)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.5.74 | 99 | 11/13/2026 |
| 1.5.59 | 1,060 | 1/27/2026 |
| 1.5.57 | 887 | 12/23/2025 |
| 1.5.40 | 2,393 | 4/18/2025 |
| 1.5.37 | 3,118 | 1/23/2025 |
| 1.5.33 | 1,610 | 12/26/2024 |
| 1.5.28 | 1,726 | 9/9/2024 |
| 1.5.18 | 2,690 | 3/29/2024 |
| 1.5.15 | 2,486 | 1/11/2024 |
| 1.5.8 | 2,007 | 6/30/2023 |
| 1.5.7 | 1,756 | 5/31/2023 |
| 1.5.0.1 | 1,862 | 3/7/2023 |
| 1.5.0 | 1,845 | 3/3/2023 |
| 1.4.49 | 1,917 | 3/3/2023 |
| 1.0.1-beta4 | 664 | 10/21/2022 |
| 1.0.1-beta3 | 316 | 10/21/2022 |
| 1.0.1-beta2 | 358 | 7/25/2022 |
| 1.0.1-beta1 | 2,375 | 6/8/2022 |
| 1.0.0-beta9 | 621 | 3/17/2022 |
| 1.0.0-beta8 | 421 | 12/21/2021 |
* Bump the minimum Akka.NET dependency to [1.5.74](https://github.com/akkadotnet/akka.net/releases/tag/1.5.74), with aligned Streams and TestKit dependencies.
* Include an individual README in each of the twelve connector packages, with usage, ownership, delivery semantics, limitations and linked NuGet version/download badges. Expand the repository README and documentation navigation.
* Update compatible Azure, AWS, AMQP and SignalR dependencies. Package READMEs document remaining SDK support and version limitations.
* Azure Service Bus JSON sources await successful message completion before emitting values and propagate settlement failures.
* Fix SQS batch-response correlation when response entries arrive in a different order.
* Improve SNS and Kinesis completion, cancellation and failure handling.
* Remove blocking SignalR send waits while preserving sequential delivery and existing materialized values.
* Propagate AMQP conversion and connection failures through the materialized completion task.
* Correct CSV parsing across split CRLF/escape sequences and XML parser empty-element/document completion, including reader and feeder cleanup.
* Improve rotating-file sink cleanup on completion and failures.
* Add required service integration, package/API, unchanged-consumer and packaged-example validation. Harden Event Hubs startup and Service Bus polling tests.
* Replace legacy FluentAssertions usages with xUnit assertions, retaining their payload, ordering, exception and deadline checks.
* Mark the historical `Akka.Streams.Channels`, `Akka.Streams.Azure.EventHub.V5` and `Akka.Streams.SignalR.AspNetCore` packages as Legacy on NuGet. See the [migration guide](https://alpakka.getakka.net/documentation/LegacyPackages.html) for their maintained replacements and compatibility requirements.
**Upstream compatibility:** Alpakka retains its public APIs and library targets. Raising the Akka.NET minimum from 1.5.60 inherits upstream binary changes: the old `RetrySupport.Retry` overload with an `int randomFactor` is replaced by a `double` overload, and `ISourceQueue<T>` requires `OfferAsync(T, CancellationToken)`. Applications using that old compiled overload or custom queue implementations need to update and rebuild against the new dependencies.