Skip to content

datagouv/datagouv-cli

Repository files navigation

datagouv-cli

CI License: MIT

datagouv-cli is a command-line tool for data.gouv.fr: work with datasets, organizations, resources, and topics from your terminal. The command is datagouv.

πŸš€ Installation

Install it on Linux, macOS, or Windows β€” no other dependency required.

Quick install (Linux / macOS)

curl -fsSL https://raw.githubusercontent.com/datagouv/datagouv-cli/main/scripts/install.sh | bash

Manual binary (all platforms)

Download the archive for your platform from GitHub Releases and install it on your PATH:

# Linux / macOS
curl -LO https://github.com/datagouv/datagouv-cli/releases/latest/download/datagouv-$(uname -s | tr '[:upper:]' '[:lower:]' | sed 's/darwin/macos/')-$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/').tar.gz
tar -xzf datagouv-*.tar.gz
sudo install -d /usr/local/lib/datagouv
sudo cp -a datagouv/. /usr/local/lib/datagouv/
sudo ln -sf /usr/local/lib/datagouv/datagouv /usr/local/bin/datagouv
# Windows
Invoke-WebRequest -Uri https://github.com/datagouv/datagouv-cli/releases/latest/download/datagouv-windows-amd64.zip -OutFile datagouv-windows-amd64.zip
Expand-Archive datagouv-windows-amd64.zip -DestinationPath .
$installDir = "$env:LOCALAPPDATA\Programs\datagouv"
New-Item -ItemType Directory -Force -Path $installDir | Out-Null
Copy-Item -Recurse -Force datagouv\* $installDir
$env:Path += ";$installDir"
[Environment]::SetEnvironmentVariable("Path", $env:Path, "User")

Manual APT (Debian / Ubuntu)

sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://datagouv.github.io/datagouv-cli/datagouv.gpg \
  | sudo gpg --dearmor -o /etc/apt/keyrings/datagouv.gpg
echo "deb [signed-by=/etc/apt/keyrings/datagouv.gpg] https://datagouv.github.io/datagouv-cli stable main" \
  | sudo tee /etc/apt/sources.list.d/datagouv.list
sudo apt update && sudo apt install datagouv

Manual Homebrew (macOS)

brew tap datagouv/datagouv-cli https://github.com/datagouv/datagouv-cli.git
brew trust datagouv/datagouv-cli
brew install datagouv

Manual Chocolatey (Windows)

From a GitHub Release (replace vX.Y.Z with the desired version):

choco install datagouv --source="https://github.com/datagouv/datagouv-cli/releases/download/vX.Y.Z"

Quick start

datagouv setup
datagouv dataset get <dataset-id>

πŸ–₯️ CLI

datagouv --help

Configuration

First set up your config:

datagouv setup

You will be asked the environment you want to interact with, and your API key. They will be stored in a config file in your home directory. If you only intend to get data, you may leave the API key blank.

Note: you may skip this setup step if you intend to target the production platform and fetch data.

To reset your settings, delete the config file with datagouv delete-config.

Displaying data

All objects have a display command that shows the object's main metadata in a human-readable way:

datagouv organization display "534fff81a3a7292c64a77e5c"
> badges: [{'kind': 'public-service'}, {'kind': 'certified'}]
> ────────────────────
> business_number_id: 12002701600563
> ────────────────────
> created_at: 2014-04-17T18:21:21.523000+00:00
> ...

Getting data

All objects also have a get command, that outputs all the object's metadata in JSON (directly fed from datagouv's API). You may for instance give the output to jq like:

datagouv organization get "534fff81a3a7292c64a77e5c" | jq .name
> "Institut national de la statistique et des Γ©tudes Γ©conomiques (Insee)"

Modifying objects

If you have run the setup command and filled in your API key, you may interact with objects (according to your rights on the platform), for instance:

datagouv dataset create --title "New dataset" --description "Nice description" --organization_id "646b7187b50b2a93b1ae3d45"
> Dataset created successfully βœ“ id is 69fb46c2bdeef492539acd61
# use the `--set` argument to update keys (can be used multiple times in one call)
datagouv dataset update "69fb46c2bdeef492539acd61" --set title="New title" --set private=true
> Dataset updated successfully βœ“
datagouv resource create "69fb46c2bdeef492539acd61" "First resource" --file-to-upload file.csv --set type=main
> Resource created successfully βœ“ id is 49e370df-cd09-4792-915b-95d25c2adc08
datagouv resource delete "49e370df-cd09-4792-915b-95d25c2adc08"
> Resource deleted successfully βœ“

Help

The --help flag is available for all subcommands.

Python library

For programmatic access to the data.gouv.fr API, see datagouv_client.

πŸ› οΈ Development

This project uses Python >=3.10,<3.15 and uv to manage dependencies.

uv sync --dev
uv run datagouv --help

Build a local binary:

uv run pyinstaller packaging/pyinstaller/datagouv.spec --clean --noconfirm
./dist/datagouv/datagouv --help

🀝 Contributing

Before contributing to the repository and making any PR, it is necessary to initialize the pre-commit hooks:

uv sync --dev
uv run pre-commit install

Once this is done, code formatting and linting, as well as import sorting, will be automatically checked before each commit.

If you cannot use pre-commit, it is necessary to format, lint, and sort imports with Ruff for linting and formatting. Either running these commands manually or installing the pre-commit hook is required before submitting contributions.

uv run ruff check --fix && uv run ruff format

🏷️ Releases and versioning

See RELEASING.md.

About

Command-line tool for data.gouv.fr: browse datasets, organizations, resources, and topics from your terminal

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors