Skip to main content

Convert Vega-Lite chart specifications to SVG, PNG, or Vega

Project description

Overview

vl-convert-python is a dependency-free Python package for converting Vega-Lite chart specifications into static images (SVG or PNG) or Vega chart specifications.

Since an Altair chart can generate Vega-Lite, this package can be used to easily create static images from Altair charts.

Try it out on Binder!
Binder

Installation

vl-convert-python can be installed using pip with

$ pip install vl-convert-python

Usage

The vl-convert-python package provides a series of conversion functions under the vl_convert module.

Convert Vega-Lite to SVG, PNG, and Vega

The vegalite_to_svg and vegalite_to_png functions can be used to convert Vega-Lite specifications to static SVG and PNG images respectively. The vegalite_to_vega function can be used to convert a Vega-Lite specification to a Vega specification.

import vl_convert as vlc

vl_spec = r"""
{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {"url": "https://raw.githubusercontent.com/vega/vega-datasets/next/data/movies.json"},
  "mark": "circle",
  "encoding": {
    "x": {
      "bin": {"maxbins": 10},
      "field": "IMDB Rating"
    },
    "y": {
      "bin": {"maxbins": 10},
      "field": "Rotten Tomatoes Rating"
    },
    "size": {"aggregate": "count"}
  }
}
"""

# Create SVG image string and then write to a file
svg_str = vlc.vegalite_to_svg(vl_spec=vl_spec)
with open("chart.svg", "wt") as f:
    f.write(svg_str)

# Create PNG image data and then write to a file
png_data = vlc.vegalite_to_png(vl_spec=vl_spec, scale=2)
with open("chart.png", "wb") as f:
    f.write(png_data)

# Create low-level Vega representation of chart and write to file
vg_spec = vlc.vegalite_to_vega(vl_spec)
with open("chart.vg.json", "wt") as f:
    f.write(vg_spec)

Convert Altair Chart to SVG, PNG, and Vega

The Altair visualization library provides a Pythonic API for generating Vega-Lite visualizations. As such, vl-convert-python can be used to convert Altair charts to PNG, SVG, or Vega. The vegalite_* functions support an optional vl_version argument that can be used to specify the particular version of the Vega-Lite JavaScript library to use. Version 4.2 of the Altair package uses Vega-Lite version 4.17, so this is the version that should be specified when converting Altair charts.

import altair as alt
from vega_datasets import data
import vl_convert as vlc

source = data.barley()

chart = alt.Chart(source).mark_bar().encode(
    x='sum(yield)',
    y='variety',
    color='site'
)

# Create SVG image string and then write to a file
svg_str = vlc.vegalite_to_svg(chart.to_json(), vl_version="4.17")
with open("altair_chart.svg", "wt") as f:
    f.write(svg_str)

# Create PNG image data and then write to a file
png_data = vlc.vegalite_to_png(chart.to_json(), vl_version="4.17", scale=2)
with open("altair_chart.png", "wb") as f:
    f.write(png_data)

# Create low-level Vega representation of chart and write to file
vg_spec = vlc.vegalite_to_vega(chart.to_json(), vl_version="4.17")
with open("altair_chart.vg.json", "wt") as f:
    f.write(vg_spec)

How it works

This crate uses PyO3 to wrap the vl-convert-rs Rust crate as a Python library. The vl-convert-rs crate is a self-contained Rust library for converting Vega-Lite visualization specifications into various formats. The conversions are performed using the Vega-Lite and Vega JavaScript libraries running in a v8 JavaScript runtime provided by the deno_runtime crate. Font metrics and SVG-to-PNG conversions are provided by the resvg crate.

Of note, vl-convert-python is fully self-contained and has no dependency on an external web browser or Node.js runtime.

Development setup

Create development conda environment

$ conda create -n vl-convert-dev -c conda-forge python=3.10 deno maturin altair pytest black black-jupyter

Activate environment

$ conda activate vl-convert-dev

Change to Python package directory

$ cd vl-convert-python

Build Rust python package with maturin in develop mode

$ maturin develop --release

Run tests

$ pytest tests

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vl_convert_python-0.3.2.tar.gz (2.7 MB view details)

Uploaded Source

Built Distributions

vl_convert_python-0.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (22.1 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

vl_convert_python-0.3.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (21.2 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

vl_convert_python-0.3.2-cp311-cp311-macosx_11_0_arm64.whl (19.5 MB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

vl_convert_python-0.3.2-cp311-cp311-macosx_10_7_x86_64.whl (20.5 MB view details)

Uploaded CPython 3.11 macOS 10.7+ x86-64

vl_convert_python-0.3.2-cp310-none-win_amd64.whl (20.8 MB view details)

Uploaded CPython 3.10 Windows x86-64

vl_convert_python-0.3.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (22.1 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

vl_convert_python-0.3.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (21.2 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

vl_convert_python-0.3.2-cp310-cp310-macosx_11_0_arm64.whl (19.5 MB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

vl_convert_python-0.3.2-cp310-cp310-macosx_10_7_x86_64.whl (20.5 MB view details)

Uploaded CPython 3.10 macOS 10.7+ x86-64

vl_convert_python-0.3.2-cp39-none-win_amd64.whl (20.8 MB view details)

Uploaded CPython 3.9 Windows x86-64

vl_convert_python-0.3.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (22.1 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

vl_convert_python-0.3.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (21.2 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

vl_convert_python-0.3.2-cp39-cp39-macosx_11_0_arm64.whl (19.5 MB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

vl_convert_python-0.3.2-cp39-cp39-macosx_10_7_x86_64.whl (20.5 MB view details)

Uploaded CPython 3.9 macOS 10.7+ x86-64

vl_convert_python-0.3.2-cp38-none-win_amd64.whl (20.8 MB view details)

Uploaded CPython 3.8 Windows x86-64

vl_convert_python-0.3.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (22.1 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

vl_convert_python-0.3.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (21.2 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

vl_convert_python-0.3.2-cp38-cp38-macosx_11_0_arm64.whl (19.5 MB view details)

Uploaded CPython 3.8 macOS 11.0+ ARM64

vl_convert_python-0.3.2-cp38-cp38-macosx_10_7_x86_64.whl (20.5 MB view details)

Uploaded CPython 3.8 macOS 10.7+ x86-64

vl_convert_python-0.3.2-cp37-none-win_amd64.whl (20.8 MB view details)

Uploaded CPython 3.7 Windows x86-64

vl_convert_python-0.3.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (22.1 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

vl_convert_python-0.3.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (21.2 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

vl_convert_python-0.3.2-cp37-cp37m-macosx_11_0_arm64.whl (19.5 MB view details)

Uploaded CPython 3.7m macOS 11.0+ ARM64

vl_convert_python-0.3.2-cp37-cp37m-macosx_10_7_x86_64.whl (20.5 MB view details)

Uploaded CPython 3.7m macOS 10.7+ x86-64

File details

Details for the file vl_convert_python-0.3.2.tar.gz.

File metadata

  • Download URL: vl_convert_python-0.3.2.tar.gz
  • Upload date:
  • Size: 2.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/0.13.6

File hashes

Hashes for vl_convert_python-0.3.2.tar.gz
Algorithm Hash digest
SHA256 a0b0827827d727a4c8d9a2989d5cfd11ba52cb9f0ff450a0dd6df33326922662
MD5 005713f7c4883f6cbaaed97f1a34ae69
BLAKE2b-256 5e73e8f70d285ffd6242b378cfc5498361a63b052d2181af03136c48ccd4bf7e

See more details on using hashes here.

File details

Details for the file vl_convert_python-0.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for vl_convert_python-0.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 abba5a2613eea1a67e850a5b63cf3cccdbe6bf00d1ff066a6f6eb9788eff5ca3
MD5 7ead480ce5159e67cef5d3fac42a6f27
BLAKE2b-256 6779f7668204d89e7c15f203bb6197f07051b20c586534b2c831cec33c681e32

See more details on using hashes here.

File details

Details for the file vl_convert_python-0.3.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for vl_convert_python-0.3.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6d6520a4df055ace9c25d552ee778ea10be2a842dd797191564224147555c64c
MD5 548be1e324ec17dc17a4ee7964f762c8
BLAKE2b-256 60f4ba5fff25f33f66f8247b66ce1bd4b0510510bf6f47fac08b992333c3b9f3

See more details on using hashes here.

File details

Details for the file vl_convert_python-0.3.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for vl_convert_python-0.3.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 97370b2d127b868ffa9555ced957fdd1ca31c78dba077b497f2e0e3ed79a6ea8
MD5 5605e5235fde53449e1f4cdde94bccf4
BLAKE2b-256 98b273ee17d27d40eab39329ac53616963f75584057c7230d918dff7b20ef826

See more details on using hashes here.

File details

Details for the file vl_convert_python-0.3.2-cp311-cp311-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for vl_convert_python-0.3.2-cp311-cp311-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 f5be69793cf84d6d7ada93ab8c5917549c760d7348cbaed6d6f3a87e9e0e51d9
MD5 4ffba4321e6bda4507b0f78eebe59deb
BLAKE2b-256 1a3362a4594d5e0baed7b84fdf552424adf0dc21e17432a1d1681505fe1055e9

See more details on using hashes here.

File details

Details for the file vl_convert_python-0.3.2-cp310-none-win_amd64.whl.

File metadata

File hashes

Hashes for vl_convert_python-0.3.2-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 190879c556a6966e22e85e3c7fa399e057bb3b8e954a35c4d8017a1844696c69
MD5 0d8c9d1fe086396892f2f515e7a434a4
BLAKE2b-256 01554c44c62cdd15cea4266ffb52b05f43835a27916527cc98b53b5119de58d6

See more details on using hashes here.

File details

Details for the file vl_convert_python-0.3.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for vl_convert_python-0.3.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f71dfa80a3daae7531d89196c01a7c3d277e57d3938101d38139a6f1df34b945
MD5 54cc6e96da7777a3b57b3e3436467b03
BLAKE2b-256 e7ebd27a8a7eb0db702a31f324bc36430b38dc8bcd118cf4e16bd445da42d840

See more details on using hashes here.

File details

Details for the file vl_convert_python-0.3.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for vl_convert_python-0.3.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 81f08b97e1f5a6ea656dcd626fc7433ef5906157534bb79239f5087788a7f4ab
MD5 eacee4a8f1401927da89d75da933b44f
BLAKE2b-256 bab2e932278967e047e53910780e3236c492282ac77b4071e9382198797aa5d3

See more details on using hashes here.

File details

Details for the file vl_convert_python-0.3.2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for vl_convert_python-0.3.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6af7333979eeab3233c1f2b23e1a8db460aba7d22305f7171fe42e1258e65b9e
MD5 d9c339a767e2486704711beed911a9b3
BLAKE2b-256 f32be9515a4bc44d38fd6891acf997f3e93787cfe5f777d8182cc1ff395135b7

See more details on using hashes here.

File details

Details for the file vl_convert_python-0.3.2-cp310-cp310-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for vl_convert_python-0.3.2-cp310-cp310-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 3de4563a13fe8370453731cc6ee43014d9a859eb1a7dc15ff89816e9b8814324
MD5 6dc2260f82c69450a13f0c7e0984fb53
BLAKE2b-256 c6ecfb9217382bfb183d96fc514df8d939d156bc5a339cc56075330438823f5a

See more details on using hashes here.

File details

Details for the file vl_convert_python-0.3.2-cp39-none-win_amd64.whl.

File metadata

File hashes

Hashes for vl_convert_python-0.3.2-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 5ebe1dc453481251d3e2d05e77ca5b237461e54aa59b26ba4a42fabf9d793f41
MD5 dc9fd651009a54c4209b97b7c52765ca
BLAKE2b-256 009f2914ae660d64fb739db9d369ad579e524102c1befb48cefc0624099b67ea

See more details on using hashes here.

File details

Details for the file vl_convert_python-0.3.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for vl_convert_python-0.3.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b7dd47eda7b01f56ba11dee3ceb1f2790c2964a3dc96beacc5e218fcc0eeef8c
MD5 90feac64fb48874ab5724d712f8aed07
BLAKE2b-256 ea963cf3e49ed0ecb3399f2d0c51c8760bc2b145c87506ef1d0057b166c59ce3

See more details on using hashes here.

File details

Details for the file vl_convert_python-0.3.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for vl_convert_python-0.3.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e3ab28ae58bed28e821522b017f3ba490b1e573e45bab17ba3e010581fdd8067
MD5 103e3b2a3060074f41d0f48453e1da20
BLAKE2b-256 0da1a94bc7329aae8350ba832150c33875a599a96b37731aff28696e1f73240e

See more details on using hashes here.

File details

Details for the file vl_convert_python-0.3.2-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for vl_convert_python-0.3.2-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 34f402c5f4fb302007470fb7669c1b8e612f66cbb46018f600db35adee987a2a
MD5 5eb12d206411ee224c3f3e5e368cb294
BLAKE2b-256 18c637cd6ee3e88adc71cb8a28270fef267acc40367818669c8fc43d5cacd93d

See more details on using hashes here.

File details

Details for the file vl_convert_python-0.3.2-cp39-cp39-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for vl_convert_python-0.3.2-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 eefcd8296d9f80ee24050e5ff7f20ffdf4958428b3e66bbef73ed433cef3ce6c
MD5 f2875f62c2e9f5cd0d097db985a0bb43
BLAKE2b-256 9d5e0c50c2b19c6f37d76b8ed2bd0b6545bbf29912c981f706f1525516163fba

See more details on using hashes here.

File details

Details for the file vl_convert_python-0.3.2-cp38-none-win_amd64.whl.

File metadata

File hashes

Hashes for vl_convert_python-0.3.2-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 5746f56a0a628b89ff527a432a8284a439f267a0281bec1d4986748935b2b9f1
MD5 1bbdd5e91729182adc5ee359af922036
BLAKE2b-256 129f7861a3ab0c9f686474e7bb0cbeee9a6f5367be17c1044e448503c6a325d3

See more details on using hashes here.

File details

Details for the file vl_convert_python-0.3.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for vl_convert_python-0.3.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 83530a0497677ec74250098407ff2d93c2290e4a461c037118077919b400195f
MD5 d7696fdd50ac2675cc5d07aa04b12fcd
BLAKE2b-256 3e42e846bb01e504f5e9438d088f06cd89b76298f1fd055568ce171408bb0837

See more details on using hashes here.

File details

Details for the file vl_convert_python-0.3.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for vl_convert_python-0.3.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b85ceec9d0d6aab207c1aff4c3228811ab8ee5546f895a88c38dc218325bac6f
MD5 0080b4f26bc4b225dd853052d37995f9
BLAKE2b-256 9f86329498e3d6312354439ef23dd3e25c3ebac74a1f907ce9569af99c3329f0

See more details on using hashes here.

File details

Details for the file vl_convert_python-0.3.2-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for vl_convert_python-0.3.2-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1a7d52ea2d5ef024ea81db2645f10dbaa847a57b4b6cda3850c4f733b21b863d
MD5 6b2d9ec165368164aa8cc07f98920343
BLAKE2b-256 7f2f02675cd81a8cf0eae43ba47c1b1158840ad8eaa9af0cbb937e561821a275

See more details on using hashes here.

File details

Details for the file vl_convert_python-0.3.2-cp38-cp38-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for vl_convert_python-0.3.2-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 7454b56cb6e58270ecc89bafa674f23b755756b5017ff415d6127441142444d1
MD5 aca8f6f4319080db5257a45c22cabb1a
BLAKE2b-256 0f0cb096a8719b55926bfd45e24bd341151d4a14533d4433cc5ff316e9e23230

See more details on using hashes here.

File details

Details for the file vl_convert_python-0.3.2-cp37-none-win_amd64.whl.

File metadata

File hashes

Hashes for vl_convert_python-0.3.2-cp37-none-win_amd64.whl
Algorithm Hash digest
SHA256 b04a42d34729bb4e72d1ec8cfbde9969ea0b3e21b093e7dcb47039d3c421b1ba
MD5 696ed14a8ce0e44719428fb5749aecd0
BLAKE2b-256 f18e2412be12325759171795e4edf6d39b968706833236783303d48ba1fc4694

See more details on using hashes here.

File details

Details for the file vl_convert_python-0.3.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for vl_convert_python-0.3.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8f0a1691198eeb41fa8b0159aa2e35c0126b02ed25e1dcb3e58a74ac29c0309d
MD5 11ceea9b486aa87afd4fc594794f2aec
BLAKE2b-256 349051a888a840d7af454b4c3b711bff4c666e89879dd941555beaf01378fb6d

See more details on using hashes here.

File details

Details for the file vl_convert_python-0.3.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for vl_convert_python-0.3.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f17cf496519dae66ea07bb64be026973a77db000671bb5af846a80a78e9e4559
MD5 c085bda8fb0f7333bdfbd02ab8457e17
BLAKE2b-256 30296637421f39df2e5b7ad49e295cc33bb710d685dc2eb439782d532185fdd3

See more details on using hashes here.

File details

Details for the file vl_convert_python-0.3.2-cp37-cp37m-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for vl_convert_python-0.3.2-cp37-cp37m-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6a2c06ec4b163162841a0a1ddc1804980400a8aa11564f0644eb6041f0e39a64
MD5 6401941996ebed2ebf5c60c61e3a4fbd
BLAKE2b-256 f26b0faf9e24d6f58831d1481039a01b517cc905777220fd44d46336b3650a0a

See more details on using hashes here.

File details

Details for the file vl_convert_python-0.3.2-cp37-cp37m-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for vl_convert_python-0.3.2-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 1ce5e2ab5535145a058fe8e041d0a671d1bde88851b1391b3effc80a9d766d39
MD5 67452cb0238e7ab6e86bd462c678f7ef
BLAKE2b-256 f139f2221f5977cd226b11f81b5b2bcbb23f71f5dac7a4d61f07b6b21020d2d7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page