
CSV
A tiny, fast Kotlin Multiplatform library for parsing and building CSV strings. Zero dependencies, explicit API, and predictable behavior.
Platforms: JVM, JS (Browser/Node), iOS, macOS, Linux, Windows
Contributions welcome — please keep the API minimalistic and self-explanatory.
Architecture
Usage
Build CSV
val csv = buildCsv {
header {
column("Code")
column("Name")
}
data {
value("DE")
value("Deutschland")
}
data {
value("BY")
value("Belarus")
}
} as CsvWithHeader
Access columns and values
val code = csv.header.columnByName("Code")!!
val name = csv.header.columnByName("Name")!!
csv.data[0][code]
csv.data[0][name]
csv.data[][code]
csv.[][name]
Convert to CSV text
val text = csv.toCsvText()
csv.toCsvText(newLine = NewLine.CRLF)
Parse CSV text
val csv = CsvWithHeader.fromCsvText("Code,Name\nDE,Deutschland\n")
val csv = CsvNoHeader.fromCsvText("DE,Deutschland\nBY,Belarus\n")
Transform data
val transformed = csv.copy(
data = csv.data.map { row ->
row.mapValueOf(name) { value ->
if (value == "Belarus") "Weißrussland" else value
}
}
)
Dependencies
In gradle/libs.versions.toml
[versions]
kotlin = "2.3.0"
csv = "1.3"
[libraries]
csv = { module = "de.halfbit:csv", version.ref = "csv" }
[plugins]
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
In shared/build.gradle.kts
plugins {
alias(libs.plugins.kotlin.multiplatform)
}
kotlin {
sourceSets {
commonMain.dependencies {
implementation(libs.csv)
}
}
}
Releasing
- Bump version in
build.gradle.kts of the root project
./gradlew clean build releaseToMavenCentral
License
Copyright 2023-2026 Sergej Shafarenka, www.halfbit.de
Licensed under the Apache License, Version 2.0 (the "License");
you may not use except compliance the License.
You may obtain a copy of the License at
http:
Unless applicable law agreed to writing, software
distributed under the License distributed an BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express implied.
See the License the specific language governing permissions
limitations under the License.