Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
X

xan

> 开发工具
Open source

The CSV magician

4.4K stars0 likes1 views
WebsiteGitHub

About

The CSV magician

xan, the CSV magician

xan is a command line tool that can be used to process CSV files directly from the shell.

It has been written in Rust to be as fast as possible, use as little memory as possible, and can very easily handle large CSV files (gigabytes to terabytes). It leverages a novel SIMD CSV parser and is also able to parallelize some computations (through multithreading) to make some tasks complete as fast as your hardware will allow.

It can easily preview, filter, slice, aggregate, sort, join CSV files, and exposes a large collection of composable commands that can be chained together to perform a wide variety of typical tabular data processing tasks.

xan also offers its own expression language so you can perform complex tasks that cannot be done by relying on the simplest commands. This minimalistic language has been tailored for CSV data and is way faster than evaluating typical script languages such as Python, Lua, JavaScript etc.

Note that this tool is originally a fork of BurntSushi's xsv, but has been nearly entirely rewritten at that point, to fit SciencesPo's médialab use-cases, rooted in web data collection and analysis geared towards social sciences (you might think CSV is outdated by now, but read our love letter to the format before judging too quickly).

xan therefore goes beyond typical data manipulation and expose utilities related to lexicometry, graph theory and even scraping.

Beyond CSV data, xan is able to process a large variety of CSV-adjacent data formats from many different disciplines such as web archival (.cdx) or bioinformatics (.vcf, .gtf, .sam, .bed etc.). xan is also able to convert to & from many data formats such as json, excel files, numpy arrays etc. using xan to and xan from. See this section for more detail.

Then, even though xan is fundamentally geared towards streams of row-oriented tabular data, it can sometimes leverage the benefits of the popular parquet file format to offer better performance. See this section for more detail.

Finally, xan can be used to display CSV files in the terminal, for easy exploration, and can even be used to draw basic data visualisations:

view command flatten command
categorical histogram scatterplot
categorical scatterplot histograms
parallel processing time series
small multiples (facet grid) grouped view
correlation matrix heatmap heatmap

Summary

  • How to install
    • Cargo
    • Scoop (Windows)
    • Homebrew (macOS)
    • Arch Linux
    • NetBSD
    • Nix
    • Pixi
    • Conda Forge
    • Pre-built binaries
    • Installing completions
  • Quick tour
  • Learning
  • Available commands
  • General flags and IO model
    • Getting help
    • Regarding input & output formats
    • Working with headless CSV file
    • Regarding stdin
    • Regarding stdout
    • Supported file formats
    • Regarding parquet files
    • Compressed files
    • Regarding color
  • Expression language reference
  • News
  • How to cite?
  • Frequently Asked Questions

How to install

Cargo

xan can be installed using cargo (it usually comes with Rust):

bash
cargo install xan --locked

You can also tweak the build flags to make sure the Rust compiler is able to leverage all your CPU's features:

bash
CARGO_BUILD_RUSTFLAGS='-C target-cpu=native' cargo install xan --locked

You can also install the latest dev version thusly:

bash
cargo install --git https://github.com/medialab/xan --locked

Scoop (Windows)

xan can be installed using Scoop on Windows:

powershell
scoop bucket add extras
scoop install xan

Homebrew (macOS)

xan can be installed with Homebrew on macOS thusly:

bash
brew install xan

Arch Linux

You can install xan from the extra repository using pacman:

bash
sudo pacman -S xan

NetBSD

A package is available from the official repositories. To install xan simply run:

pkgin install xan

Nix

xan is packaged for Nix, and is available in Nixpkgs as of 25.05 release. To install it, you may add it to your environment.systemPackages as pkgs.xan or use nix-shell to enter an ephemeral shell.

bash
nix-shell -p xan

Pixi (Linux, macOS, Windows)

xan can be installed in Linux, macOS, and Windows using the Pixi package manager:

bash
pixi global install xan

Conda Forge

xan can be installed through conda-forge thusly:

bash
conda install conda-forge::xan

Pre-built binaries

Pre-built binaries can be found attached to every GitHub releases.

Currently supported targets include:

  • x86_64-apple-darwin

  • x86_64-unknown-linux-gnu

  • x86_64-unknown-linux-musl

  • x86_64-pc-windows-msvc

  • aarch64-apple-darwin

  • aarch64-unknown-linux-gnu

ppc64le targets are not built by the CI yet but prebuilt binaries can still be found in the conda-forge package's files if you need them.

Feel free to open a PR to improve the CI by adding relevant targets.

Installing completions

Note that xan also exposes handy automatic completions for command and header/column names that you can install through the xan completions command.

Run the following command to understand how to install those completions:

bash
xan completions -h

For zsh, you can add the completion file to ~/.zfunc:

bash
mkdir -p ~/.zfunc
xan completions zsh > ~/.zfunc/_xan

Then add this before compinit in your ~/.zshrc:

bash
fpath=(~/.zfunc $fpath)
autoload -Uz compinit
compinit

Quick tour

Let's learn about the most commonly used xan commands by exploring a corpus of French medias:

Downloading the corpus

bash
curl -LO https://github.com/medialab/corpora/raw/master/polarisation/medias.csv

Displaying the file's headers

bash
xan headers medias.csv
0   webentity_id
1   name
2   prefixes
3   home_page
4   start_pages
5   indegree
6   hyphe_creation_timestamp
7   hyphe_last_modification_timestamp
8   outreach
9   foundation_year
10  batch
11  edito
12  parody
13  origin
14  digital_native
15  mediacloud_ids
16  wheel_category
17  wheel_subcategory
18  has_paywall
19  inactive

Counting the number of rows

bash
xan count medias.csv
478

Previewing the file in the terminal

bash
xan view medias.csv
…

On unix, don't hesitate to use the -p flag to automagically forward the full output to an appropriate pager and skim through all the columns.

Reading a flattened representation of the first row

bash
# NOTE: drop -c to avoid truncating the values
xan flatten -c medias.csv
…

Searching for rows

bash
xan search -s outreach internationale medias.csv | xan view -s name,outreach
…

Selecting some columns

bash
xan select foundation_year,name medias.csv | xan view
…

Sorting the file

bash
xan sort -s foundation_year medias.csv | xan view -s name,foundation_year
…

Deduplicating the file on some column

bash
# Some medias of our corpus have the same ids on mediacloud.org
xan dedup -s mediacloud_ids medias.csv | xan count && xan count medias.csv
457
478

Deduplicating can also be done while sorting:

bash
xan sort -s mediacloud_ids -u medias.csv

Computing frequency tables

bash
xan frequency -s edito medias.csv | xan view
Displaying 3 cols from 5 rows of <stdin>
┌───┬───────┬────────────┬───────┐
│ - │ field │ value      │ count │
├───┼───────┼────────────┼───────┤
│ 0 │ edito │ media      │ 423   │
│ 1 │ edito │ individu   │ 30    │
│ 2 │ edito │ plateforme │ 14    │
│ 3 │ edito │ agrégateur │ 10    │
│ 4 │ edito │ agence     │ 1     │
└───┴───────┴────────────┴───────┘

Printing a histogram

bash
xan frequency -s edito medias.csv | xan hist
Histogram for edito (bars: 5, sum: 478, max: 423):

media      |423  88.49%|━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━|
individu   | 30   6.28%|━━━╸                                                  |
plateforme | 14   2.93%|━╸                                                    |
agrégateur | 10   2.09%|━╸                                                    |
agence     |  1   0.21%|╸                                                     |

Computing descriptive statistics

bash
xan stats -s indegree,edito medias.csv | xan transpose | xan view -I
…

Evaluating an expression to filter a file

bash
xan filter 'batch > 1' medias.csv | xan count
130

Note that the expression language distinguishes between arithmetic & string operators. Filtering on the media column which contains strings, for instance, you would rather use the eq operator than the == one that should be used for numbers:

bash
xan filter 'edito eq "plateforme"'

This said, for this particular use-case you should often stick to xan search instead.

To access the expression language's cheatsheet, run xan help cheatsheet. To display the full list of available functions, run xan help functions.

Evaluating an expression to create a new column based on other ones

bash
xan map 'fmt("{} ({})", name, foundation_year) as key' medias.csv | xan select key | xan slice -l 10
key
Acrimed.org (2002)
24matins.fr (2006)
Actumag.info (2013)
2012un-Nouveau-Paradigme.com (2012)
24heuresactu.com (2010)
AgoraVox (2005)
Al-Kanz.org (2008)
Alalumieredunouveaumonde.blogspot.com (2012)
Allodocteurs.fr (2005)
Alterinfo.net (2005)

To access the expression language's cheatsheet, run xan help cheatsheet. To display the full list of available functions, run xan help functions.

Transform a column by evaluating an expression

bash
xan transform name 'split(name, ".") | first | upper' medias.csv | xan select name | xan slice -l 10
name
ACRIMED
24MATINS
ACTUMAG
2012UN-NOUVEAU-PARADIGME
24HEURESACTU
AGORAVOX
AL-KANZ
ALALUMIEREDUNOUVEAUMONDE
ALLODOCTEURS
ALTERINFO

To access the expression language's cheatsheet, run xan help cheatsheet. To display the full list of available functions, run xan help functions.

Performing custom aggregation

bash
xan agg 'sum(indegree) as total_indegree, mean(indegree) as mean_indegree' medias.csv | xan view -I
Displaying 1 col from 1 rows of <stdin>
┌────────────────┬───────────────────┐
│ total_indegree │ mean_indegree     │
├────────────────┼───────────────────┤
│ 25987          │ 56.12742980561554 │
└─────────

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rustclicsvrusttsv

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category开发工具
PricingOpen source

> Related tools

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具