dataload
A flexible Rust library for loading CSV and Excel files into Polars DataFrames.
Features
- Automatic file type detection via magic bytes and file extensions
- Smart delimiter detection for CSV files (comma, tab, semicolon, pipe)
- Excel support for xlsx, xls, xlsm, xlsb, and ods formats
- Builder-pattern API for flexible configuration
- Feature flags to minimize dependencies
Installation
Add to your Cargo.toml:
[]
= "0.1"
To disable Excel support (reduces compile time and dependencies):
[]
= { = "0.1", = false, = ["csv"] }
Quick Start
use ;
use Path;
// Simple one-liner
let df = load_file?;
// From bytes
let csv_data = b"name,age\nAlice,30\nBob,25";
let df = load_bytes?;
// With custom options
let df = new
.with_delimiter
.with_header
.with_skip_rows
.with_max_rows
.load_file?;
CSV Loading
The library automatically detects the delimiter by analyzing the file content:
use load_bytes;
// Auto-detects comma delimiter
let df = load_bytes?;
// Auto-detects tab delimiter
let df = load_bytes?;
// Auto-detects semicolon delimiter
let df = load_bytes?;
Or specify a delimiter explicitly:
use ;
let df = new
.with_delimiter
.load_bytes?;
Excel Loading
use DataLoader;
use Path;
// Load first sheet (default)
let df = new
.load_file?;
// Load specific sheet by name
let df = new
.with_sheet_name
.load_file?;
// Load specific sheet by index (0-based)
let df = new
.with_sheet_index
.load_file?;
// List available sheets
let sheets = list_sheets?;
Configuration Options
| Option | Description | Default |
|---|---|---|
delimiter |
CSV delimiter (Auto, Comma, Tab, Semicolon, Pipe, Custom(u8)) |
Auto |
has_header |
First row is header | true |
skip_rows |
Rows to skip from start | 0 |
max_rows |
Maximum rows to read | None (all) |
sheet_index |
Excel sheet index (0-based) | None (first) |
sheet_name |
Excel sheet name | None |
infer_schema |
Infer column types | true |
infer_schema_length |
Rows for type inference | Some(1000) |
Error Handling
All operations return Result<T, DataLoadError>:
use ;
use Path;
match load_file
Feature Flags
| Feature | Description | Default |
|---|---|---|
csv |
CSV/TSV file support | ✓ |
excel |
Excel file support (xlsx, xls, etc.) | ✓ |
License
Licensed under Apache License, Version 2.0
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.