Skip to main content

Altair Saver

github actions github actions code style black Open in Colab

This packge provides extensions to Altair for saving charts to a variety of output types. Supported output formats are:

  • .json/.vl.json: Vega-Lite JSON specification
  • .vg.json: Vega JSON specification
  • .html: HTML output
  • .png: PNG image
  • .svg: SVG image
  • .pdf: PDF image

Usage

The altair_saver library has a single public function, altair_saver.save(). Given an Altair chart named chart, you can use it as follows:

from altair_saver import save

save(chart, "chart.vl.json")              # Vega-Lite JSON specification
save(chart, "chart.vg.json")              # Vega JSON specification
save(chart, "chart.html")                 # HTML document
save(chart, "chart.html", inline=True)    # HTML document with all JS code included inline
save(chart, "chart.png")                  # PNG Image
save(chart, "chart.svg")                  # SVG Image
save(chart, "chart.pdf")                  # PDF Image

Renderer

Additionally, altair_saver provides an Altair Renderer entrypoint that can display the above outputs directly in Jupyter notebooks. For example, you can specify a vega-lite mimetype (supported by JupyterLab, nteract, and other platforms) with a PNG fallback for other frontends as follows:

alt.renderers.enable('altair_saver', ['vega-lite', 'png'])

Installation

The altair_saver package can be installed with:

$ pip install git+https://github.com/altair-viz/altair_saver.git

Saving as vl.json and as html requires no additional setup.

To save charts in other formats requires additional dependencies in order to execute the javascript code used to render and save Altair charts. altair_saver provides interfaces to two different backends, respectively based on Selenium and NodeJS.

Selenium

The selenium backend supports the following formats:

  • .vg.json
  • .png
  • .svg.

To be used, it requires the Selenium Python package, and a properly configured installation of either chromedriver or geckodriver.

On Linux systems, this can be setup as follows:

$ pip install selenium
$ apt-get install chromium-chromedriver

Using conda, the required packages can be installed as follows (a compatible version of Google Chrome must be installed separately):

$ conda install -c python-chromedriver-binary

Selenium supports other browsers as well, but altair-saver is currently only tested with Chrome.

NodeJS

The nodejs backend supports the following formats:

  • .vg.json
  • .png
  • .svg
  • .pdf

It requires NodeJS, along with the vega-lite, vega-cli, and canvas packages.

First install NodeJS either by direct download or via a package manager, and then use the npm tool to install the required packages:

$ npm install vega-lite vega-cli canvas

Using conda, node and the required packages can be installed as follows:

$ conda install -c conda-forge nodejs
$ npm install -g vega-lite vega-cli canvas

Release files for altair-saver 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for altair-saver 0.1.0
File Size Uploaded
altair_saver-0.1.0.tar.gz 97.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for altair-saver 0.1.0
File Interpreter ABI Platform
altair_saver-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 199.1 kB

Release files / altair_saver-0.1.0.tar.gz

Download URL altair_saver-0.1.0.tar.gz
Size 97.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0c6eea22b7651123594a3fed97074941ceb571ab7738633a62f28191d17b96da
BLAKE2b-256 checksum
How to use checksums
b23ad2b160356f152ae3023a0f5614692d67613747c902fa34a504b05b00f658
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2.post20191203 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.7.5

Release files / altair_saver-0.1.0-py3-none-any.whl

Download URL altair_saver-0.1.0-py3-none-any.whl
Size 101.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b17a57a1394a668606f48831e2212eb0b6e90e6e42034d4967148890db1c77dc
BLAKE2b-256 checksum
How to use checksums
2188f9b85386fee1a483c96afb0460c9e7188a6c8613783e043432e89621d1da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2.post20191203 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.7.5

Release history Release notifications | RSS feed

0.5.0

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page