VegaFusion
VegaFusion provides server-side acceleration for the Vega visualization grammar, primarily designed to enhance Python libraries like Altair. It enables scaling interactive charts to large datasets by offloading data transformations from the browser to an efficient, multi-threaded Rust-based Python kernel. The library is currently at version 2.0.3 and maintains an active development and release cadence.
Warnings
- breaking VegaFusion 2.0 removed the `vegafusion-jupyter` package and direct Altair integration methods (like `vf.enable()`, `vf.save()`, `vf.transformed_data()`) from the `vegafusion` package. These functionalities are now handled directly by Altair's built-in 'vegafusion' data transformer.
- breaking VegaFusion 2.0 requires Altair version 5.5.0 or higher for full compatibility. Older Altair versions may not work or exhibit unexpected behavior.
- breaking VegaFusion 2.0 significantly reduced its Python dependencies. `pyarrow` and `pandas` are no longer required, instead relying on `narwhals` for DataFrame compatibility and `arrow3-core` for Arrow data. Existing code heavily dependent on `pyarrow` or `pandas` might need adjustments if not explicitly installed alongside.
- gotcha When working in cloud notebook environments, VegaFusion's local timezone might differ from the browser's. This can lead to discrepancies in date/time-based visualizations or transformations.
Install
-
pip install vegafusion altair
Imports
- vegafusion
import vegafusion as vf
- enable/save/transformed_data (for Altair)
import vegafusion as vf; vf.enable()
import altair as alt alt.data_transformers.enable('vegafusion')
Quickstart
import altair as alt
from vega_datasets import data
# Enable the VegaFusion data transformer within Altair
alt.data_transformers.enable('vegafusion')
# Example Altair chart that benefits from VegaFusion's server-side processing
source = data.flights.url
chart = alt.Chart(source).mark_bar().encode(
x=alt.X('distance:Q', bin=True),
y='count()'
).properties(title='Flight Distance Histogram (Accelerated by VegaFusion)')
# To display the chart in a Jupyter environment:
chart
# To save the chart with transformed data (using Altair's native save method):
# chart.save('flight_histogram.json')