Kotools CSV is a lightweight library for managing CSV files with elegant Kotlin DSLs.
data class Person(val name: String, val age: Int, val isAdmin: Boolean = false)
suspend fun main() {
csvWriter<Person> {
file = "people"
records { +Person("Nobody", 25) }
}
val people: List<Person> = csvReader { file = "people" }
println(people)
}
Kotools CSV just ship with what you need for manipulating CSV files, and has only 3 direct dependencies:
- doyaaaaaken/kotlin-csv for reading and writing in CSV files
- kotlin-reflect for parsing custom types to or from CSV records
- Kotlin/kotlinx.coroutines for running processes asynchronously.
Kotools CSV lets you choose explicitly how to handle errors following the design
of Kotlin Standard Library: if
something goes wrong, functions suffixed by OrNull
will return null
and
other functions will throw an IllegalStateException
. With this explicit
design, you can orchestrate easily your application state in production.
This library provides intuitive type-safe builders (also known as DSLs) for readability and maintainability purpose. So you can focus on what's important in your code, instead of trying to guess what is the good way to retrieve a file from resources or a file only present at runtime. Simplicity is key.
implementation("io.github.kotools:csv:2.2.0")
implementation 'io.github.kotools:csv:2.2.0'
<dependency>
<groupId>io.github.kotools</groupId>
<artifactId>csv</artifactId>
<version>2.2.0</version>
</dependency>
Latest documentation of Kotools CSV is available here. Also, you can find more information about CSV format in the RFC 4180.
Feel free to contribute to the project with issues and pull requests.
This project is licensed under the MIT License.