Scripts for interacting with the Datawrapper API.
Scripts do not currently make edits to charts within Datawrapper. The only active change possible in Datawrapper is publishing unpublished charts in collect_charts_for_export().
├── temp/
├── .gitignore
├── .pre-commit-config.yaml
├── export_charts.py
├── get_chart_details.py
├── README.md
└── utils.py
| File | Description |
|---|---|
get_chart_details.py |
Gets details of all charts in a Datawrapper folder, including embed codes, and saves them to Excel. |
export_charts.py |
Exports charts as PNGs and/or SVGs, optionally publishing unpublished charts first. |
utils.py |
Shared utility functions used by the scripts above. |
The scripts require a Datawrapper API token to be stored in a DATAWRAPPER_API_TOKEN environment variable.
| Variable | Description |
|---|---|
DATAWRAPPER_API_TOKEN |
Datawrapper API token |
To use collect_charts_for_export() with default arguments, this needs to have the following scopes:
chart:read, writefolder:readtheme:readvisualization:read
To use export_charts() with publish=False, the required scopes are only:
chart:readfolder:read
Note that in Datawrapper, API tokens are all associated with a user account (verifiable by creating a token with the user:read scope and calling the me endpoint).
This project uses pre-commit hooks to ensure code quality. To set up:
- Install
pre-commiton your system if you don't already have it:pip install pre-commit
- Set up
pre-commitin your copy of this project. In the project directory, run:pre-commit install
Rules that are applied can be found in .pre-commit-config.yaml.
The hooks run automatically on commit, or manually with pre-commit run --all-files.