vega / altair

Declarative statistical visualization library for Python
https://altair-viz.github.io/
BSD 3-Clause "New" or "Revised" License
9.36k stars 794 forks source link

Define `vl-convert-python` dependency outside of `altair[all]` #3608

Closed apoorvkh closed 2 weeks ago

apoorvkh commented 1 month ago

What is your suggestion?

The vl-convert-python package is necessary for saving plots in PNG / SVG / PDF formats. I believe this is a rather critical function, so I'm wondering why vl-convert-python needs to be manually installed for this capability. (I see that altair[all] is an alternative, but I think vega_datasets, etc. are less critical than the save functionality.)

vl-convert-python has zero dependencies. So I think this would be a simple addition. Maybe that is the reason Is this dependency optional because the built wheels are ~30 MB? Could this size be reduced?

Thanks so much for your consideration!

Have you considered any alternative solutions?

Alternatively, could this (at least) be added to a new optional dependency group altair[save], as suggested here?

jonmmease commented 1 month ago

Hi @apoorvkh, As you noticed, vl-convert-python is a native compiled wheel, and it's fairly large. Both of these are consequences of the fact that vl-convert embeds the V8 JavaScript runtime (through the Deno project) in order to run the Vega-Lite and Vega JavaScript libraries without external dependencies. There is no obvious way, that I'm aware of, to reduce the size of vl-convert without reducing functionality.

This can't be a required dependency of the altair package, because it would prevent Altair's use in architectures that aren't supported by Deno, but do run Python. A prominent example of this is Pyodide, for running Python in the browser.

I don't have a problem with adding an additional dependency group, but could you say more about why you wouldn't want to use the all group?

apoorvkh commented 1 month ago

Thanks a lot for the explanation!

could you say more about why you wouldn't want to use the all group?

I just want to use Altair to plot / interact with my data and save to a static file, so I can put figures in my academic papers. I simply don't need any of these (besides vl-convert-python)! So I prefer not to depend on them (if I can) to avoid potential conflicts. And I am just bringing this up, because I feel that saving plots to static files is a rather core functionality.

https://github.com/vega/altair/blob/712680b2965eede4c40d93f52d3f963c5d181587/pyproject.toml#L57-L66

E.g. not even pandas because I am using polars; surprisingly, not even numpy, because torch seems to cover everything I need that is ML-related.

apoorvkh commented 1 month ago

I made a simple PR with the change, in case this is sufficiently compelling to you. Please let me know, thanks!

https://github.com/vega/altair/pull/3609