Skip to main content

Add your description here

Project description

Django Altair Express

A Django package that provides a reusable template tag for rendering Altair charts.

Installation

pip install django-altair-express

or with uv:

uv add django-altair-express

Add the application to your INSTALLED_APPS in settings.py:

INSTALLED_APPS = [
    # ...
    'django_altair_express',
]

Requirements for Vega

For the charts to render correctly, you must include the exact versions of the Vega, Vega-Lite, and Vega-Embed libraries in your HTML. Please add these scripts to your base template <head> or before the end of the <body>:

<!-- Exact required versions for compatibility -->
<script src="https://cdn.jsdelivr.net/npm/vega@5.30.0"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-lite@5.21.0"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-embed@6.26.0"></script>

Usage

In your Django view, create an Altair chart and pass it to the template context:

import altair as alt
from django.shortcuts import render

def my_view(request):
    chart = alt.Chart(alt.Data(values=[{"x": 1, "y": 2}])).mark_point().encode(x='x:Q', y='y:Q')
    return render(request, 'my_template.html', {'chart': chart})

In your template (my_template.html), load the template tags and use the render_altair tag:

{% load altair_express %}

<!DOCTYPE html>
<html>
<head>
    <!-- Include Vega scripts here -->
</head>
<body>
    <h1>My Chart</h1>
    <!-- Renders the container and javascript for the chart -->
    {% render_altair chart %}
</body>
</html>

The render_altair tag accepts:

  • An Altair chart object (which implements .to_json())
  • A Python dictionary representing the Vega-Lite JSON specification
  • A JSON string representing the Vega-Lite specification

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

django_altair_express-0.1.0.tar.gz (2.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_altair_express-0.1.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file django_altair_express-0.1.0.tar.gz.

File metadata

  • Download URL: django_altair_express-0.1.0.tar.gz
  • Upload date:
  • Size: 2.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for django_altair_express-0.1.0.tar.gz
Algorithm Hash digest
SHA256 59f39dac8a928691e12af1d01dca3e36f5c93584d31098c43f95e2caf08dbbf2
MD5 39f00f21f817f514d5dfa6fadf579da1
BLAKE2b-256 567111f20718210849cd2ecd6648bcc4ad5f063a5d7ae6ce7e694f40de1f6032

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_altair_express-0.1.0.tar.gz:

Publisher: ci.yml on Xpt0xZv/django_altair_express

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_altair_express-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_altair_express-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 00bcab7f11151f8a26462e4a6ebd190e8be8b9bd463b3ae68777a0ad86640893
MD5 b54809e36aba11a3d967c676766b9087
BLAKE2b-256 af69386377e3bc28c3cc19df96ec374ae3fa6b09592b1d3f2e7c6a9d306f6a96

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_altair_express-0.1.0-py3-none-any.whl:

Publisher: ci.yml on Xpt0xZv/django_altair_express

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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