swiss-apis-cli
v1.0.0
Published
CLI for Swiss public APIs: transport, geo.admin.ch, opendata.swiss, Fedlex, OpenParlData, and more
Maintainers
Readme
swiss-apis-cli
Command-line interface to query Swiss public data and open APIs from the terminal. Commands are named with a swiss_* prefix (for example swiss_transport_connections, swiss_geo_get_elevation). Run swiss list to see every command and a short description.
Runtime: Node.js 18+.
What it talks to
The CLI calls (or points to) the services below. Availability, rate limits, and terms of use are defined by each operator—not by this project.
| Domain | Service | Role in the CLI |
|--------|---------|------------------|
| Public transport | transport.opendata.ch (/v1) | Station boards, connections, station/location search. |
| Public transport (real-time) | OpenTransportData Swiss | GTFS real-time feeds via api.opentransportdata.swiss (API key required). |
| Maps & geodesy | swisstopo / geo.admin.ch | api3.geo.admin.ch — search, identify canton/municipality, elevation; geodesy.geo.admin.ch/reframe — coordinate transforms; wmts.geo.admin.ch — WMTS tile URL helpers. |
| Open government data | opendata.swiss CKAN API | ckan.opendata.swiss/api/3/action — dataset search for health (BAG), energy, MeteoSwiss-related datasets, BFS statistics, SNB, SEM migration, etc. |
| Federal law | Fedlex | SPARQL endpoint fedlex.data.admin.ch/sparqlendpoint for in-force legislation search. |
| Parliament | OpenParlData CH | api.openparldata.ch — search and person listings. |
| Electricity grid | Swissgrid (open data) | Energy datasets and references surfaced via CKAN / Swissgrid-related queries in the CLI. |
| Hydrology | hydrodaten.admin.ch | Hydrological data; linked open data via environment.ld.admin.ch (LINDAS) where applicable. |
| Avalanches / snow | SLF | Avalanche and snow-related open data (often via opendata.swiss CKAN). |
| Weather | MeteoSwiss open data | Datasets catalogued on opendata.swiss. |
| Health | BAG / FOPH datasets on opendata.swiss; Versorgungsatlas | CKAN search and dataset metadata; atlas references where implemented. |
| Postal & places | OpenPLZ API | openplzapi.org/ch — localities, postal codes (no API key). |
| National Bank | data.snb.ch | SNB datasets on opendata.swiss plus API endpoint data.snb.ch/api in responses. |
| Commercial register | ZEFIX | ZefixPublicREST — company search and related calls (account required). |
| Food products | FoodRepo | foodrepo.org/api/v3 — product search (API token). |
| Food composition | Nährwertdaten (FSVO) | The swiss_food_nutrition_database command returns links and hints to the official portal; it does not scrape or call a separate JSON API. |
| Migration statistics | SEM | SEM statistics portal links plus SEM datasets via opendata.swiss CKAN. |
Install
npm install -g swiss-apis-cliFrom a clone, run npm install && npm run build, then node dist/cli.js or use npm run dev with tsx.
Configuration
- Optional
.envin the current working directory when you runswiss— copy.env.exampleto.envand set only what you need. Comments in.env.examplelink to official registration pages. - Optional key file:
~/.swiss-apis-cli/keys(linesKEY=value). Values are merged into the process environment if not already set.
Variables used by the CLI:
| Variable | Used for |
|----------|----------|
| OTD_API_KEY | GTFS real-time / OpenTransportData Swiss |
| ZEFIX_USER, ZEFIX_PASS | ZEFIX REST API |
| FOODREPO_API_KEY | FoodRepo product API |
Usage
swiss list
swiss list --json
swiss info swiss_transport_stationboard
swiss call swiss_transport_stationboard '{"station":"Bern","limit":3}'
echo '{"from":"Bern","to":"Genève"}' | swiss call swiss_transport_connections -
swiss call swiss_geo_get_elevation @args.json
swiss doctor # same as swiss call swiss_check_setupswiss check_setup (and swiss doctor) summarizes which optional credentials are present—without printing secret values.
Tests
npm test— fast tests, no network (registry, validation, localswiss_check_setupbehaviour).npm run test:integration— live HTTP against the public services above. Requires internet; may fail if an upstream API is down or has changed.npm run test:all— runs both.
Some integration cases are skipped unless OTD_API_KEY, ZEFIX_*, or FOODREPO_API_KEY are set.
Licence
MIT — see LICENSE.
