Skip to main content

Add your description here

Project description

Django Altair Express

CI PyPI version Python Versions

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

Requirements

  • Python: 3.10, 3.11, 3.12, 3.13
  • Django: 4.2 or higher
  • Altair: 5.0 or higher

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.2.tar.gz (2.6 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.2-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_altair_express-0.1.2.tar.gz
  • Upload date:
  • Size: 2.6 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.2.tar.gz
Algorithm Hash digest
SHA256 bb1f0cec09b1e459f4d6e2c86a6d5ded88f4fd8ee84064d124d766df5692eaf8
MD5 6fc9cb5489224428e5469d2eec8fe05c
BLAKE2b-256 ef8caab4fe406370251aa21c3a5a13576618a0b523c6162e4e4f8a1174e9fed1

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_altair_express-0.1.2.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.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_altair_express-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 05966a6cd596b1132ecff8d8e939e72a1346e2c41e63e38e0ff9e5c8c51cfbbc
MD5 d726269651ae3011207992d9232c8e90
BLAKE2b-256 1aa5e1bc726a9db8c19ce0bd0dea389ceb692fefdb10e452907d6d1702ff7b71

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_altair_express-0.1.2-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