Altex
Altex is a Python library that provides a simplified, expressive API wrapper around Altair, designed to facilitate quick chart creation, especially within Streamlit applications. It aims to reduce the boilerplate code typically associated with Altair. The library is currently at version 0.2.0 and has an active development status, with its latest release in late 2025 focusing on dependency reduction and compatibility improvements.
Common errors
-
ModuleNotFoundError: No module named 'altex'
cause The 'altex' library is not installed in your current Python environment.fixInstall the library using pip: `pip install altex` -
TypeError: 'dict' object has no attribute 'line_chart' (or similar AttributeError)
cause This error often occurs if 'altex' was not imported correctly, or if you're attempting to call an Altex function on a non-Altex object, such as a dictionary, confusing it with the 'altex' module.fixEnsure you have `import altex` at the top of your script and are calling functions directly from the `altex` module, e.g., `altex.line_chart(...)`. -
Chart does not display when running script outside Streamlit/Jupyter
cause Altex charts return an Altair Chart object. In non-interactive environments or outside of Streamlit, this object needs to be explicitly rendered or saved.fixTo display the chart, add `.display()` to your chart creation call (e.g., `altex.line_chart(data, x, y).display()`) which will typically open it in your browser. Alternatively, save it to a file: `chart.save('my_chart.html')`.
Warnings
- breaking The v0.2.0 release included 'Fixed Altair theme API for backward compatibility'. If you were relying on previous (potentially buggy) Altair theme behavior or directly manipulating Altair themes with Altex prior to 0.2.0, this fix might introduce behavioral changes.
- gotcha Altex provides automatic Streamlit integration. If a chart is created within a Streamlit application context, it will attempt to render directly in Streamlit. Outside of Streamlit, Altex charting functions return an Altair Chart object, which needs an explicit `.display()` call to be rendered in environments like Jupyter notebooks.
Install
-
pip install altex
Imports
- altex
import altex
- line_chart
from altex import line_chart
altex.line_chart(...)
Quickstart
import altex
import pandas as pd
import streamlit as st # Optional, for rendering in Streamlit
# Create sample data
data = pd.DataFrame({
'x': range(10),
'y': [i**2 for i in range(10)]
})
st.set_page_config(layout='wide') # Optional, for Streamlit layout
st.title('Altex Quickstart Chart')
# Create and display charts
st.write("### Line Chart")
altex.line_chart(data=data, x='x', y='y', title='My Line Chart').display() # .display() for non-Streamlit environments
st.write("### Bar Chart with Color")
altex.bar_chart(data=data, x='x', y='y', color='x', title='My Bar Chart').display() # .display() for non-Streamlit environments