This project is a containerized, self-hosted version of the Vega VL-Convert Service. It migrates the original Vercel serverless functions to a Flask web application that can be deployed in Docker containers for better control, reliability, and integration with your own infrastructure.
- Self-hosted: Run on your own servers instead of relying on external services
- Docker containerized: Easy deployment and scaling
- API compatible: Maintains the same API endpoints as the original Vercel service
- Optimized fonts: Uses web-optimized WOFF fonts downloaded from CDN during build
- Production ready: Includes gunicorn WSGI server and proper security practices
The service provides a REST API to VlConvert for converting Vega-Lite and Vega specifications to various formats.
The following endpoints are available
All the endpoints that accept a Vega-Lite specification support a query parameter named vl_version, which defines the version of the Vega-Lite library that should be used. See VlConvert Release Notes for info on the supported versions. Defaults to the latest Vega-Lite version.
Retrieve the version of VlConvert that is backing the API
Compile a Vega-Lite spec to a Vega spec. The Vega-Lite spec should be provided as the request body. The following optional query parameters are supported:
vl_version: The Vega-Lite version.
Convert a Vega-Lite spec to an SVG image. The Vega-Lite spec should be provided as the request body. The following optional query parameters are supported:
vl_version: The Vega-Lite version.theme: Named theme as supported by vega-themes.
Convert a Vega-Lite spec to a PNG image. The Vega-Lite spec should be provided as the request body. The following optional query parameters are supported:
vl_version: The Vega-Lite version.theme: Named theme as supported by vega-themes.scale: Scale factor for the resulting image size. Defaults to 1.ppi: Pixel's per inch of the resulting image. Defaults to 72.
Convert a Vega-Lite spec to a PDF document. The Vega-Lite spec should be provided as the request body. The following optional query parameters are supported:
vl_version: The Vega-Lite version.theme: Named theme as supported by vega-themes.scale: Scale factor for the resulting image size. Defaults to 1.
Convert a Vega spec to an SVG image. The Vega spec should be provided as the request body..
Convert a Vega spec to a PNG image. The Vega spec should be provided as the request body. The following optional query parameters are supported:
scale: Scale factor for the resulting image size. Defaults to 1.ppi: Pixel's per inch of the resulting image. Defaults to 72.
Convert a Vega spec to a PDF document. The Vega spec should be provided as the request body. The following optional query parameters are supported:
scale: Scale factor for the resulting image size. Defaults to 1.
Here is an example of converting a Vega-Lite spec to a PNG image using curl. A 2.0 scale factor and dark theme are specified as query parameters.
Example using your self-hosted service:
curl -X POST "http://localhost:8080/api/vl2png?scale=2.0&theme=dark" \
-d '{"$schema": "https://vega.github.io/schema/vega-lite/v5.json", "data": {"url": "data/movies.json"}, "mark": "circle", "encoding": {"x": {"bin": {"maxbins": 10}, "field": "IMDB Rating"}, "y": {"bin": {"maxbins": 10}, "field": "Rotten Tomatoes Rating"}, "size": {"aggregate": "count"}}}' \
-o chart.pngBuild and run the containerized service:
# Build the Docker image
docker build -t vl-convert-service .
# Run the container
docker run -p 8080:8080 vl-convert-serviceOr use Docker Compose for easier development:
# Start the service
docker-compose up
# Stop the service
docker-compose downThe service will be available at http://localhost:8080
For local development without Docker:
# Create virtual environment
python3 -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Run the Flask application
python app.pyTest the service with the included validation script:
python verify_migration.pyThis validates that all endpoints are working correctly and producing the expected responses.