ChartJS Python integration
Project description
pydacharts
Pydantic :heart: chartjs This is a code generator for ChartJS configuration JSON.
Set Up
- Pip install the package with
pip install pydacharts
,uv add pydacharts
, or clone the repo - Use the class generator to write a "config" file. One simple example
from pydacharts.models import Config, Data, Dataset
def spending_by_year_chartjs() -> Config:
"""
Return a chartjs "config" object for sip dataset
charting
"""
return Config(
type="bar",
data=Data(
labels=["Green is nice", "Red is angry", "Blue is calming"],
datasets=[Dataset(
backgroundColor = ["green", "red", "blue"],
data = [1,2,3],
label = "We love colors"
)]
)
)
(This example should work standalone)
For running examples
Run Examples
uv sync --extra serve
uv .venv/bin/activate
cd serve
fastapi run
go to localhost:8000
Dev
Linting is done with ruff & mypy, testing with pytest. Expected output is like this:
(pydacharts) josh@carbonmint:~/github/catalpainternational/pydacharts$ uv run mypy .
Success: no issues found in 25 source files
(pydacharts) josh@carbonmint:~/github/catalpainternational/pydacharts$ uv run ruff check --fix .
All checks passed!
(pydacharts) josh@carbonmint:~/github/catalpainternational/pydacharts$ uv run pytest
===================================================================================================================== test session starts =====================================================================================================================
platform linux -- Python 3.11.10, pytest-8.3.3, pluggy-1.5.0
rootdir: /home/josh/github/catalpainternational/pydacharts
configfile: pyproject.toml
plugins: cov-5.0.0, anyio-4.6.0
collected 41 items
tests/test_bar.py ..... [ 12%]
tests/test_chart_examples.py .. [ 17%]
tests/test_chart_utils.py .... [ 26%]
tests/test_datalabels.py . [ 29%]
tests/test_elements.py .... [ 39%]
tests/test_line.py .... [ 48%]
tests/test_models.py .................. [ 92%]
tests/test_options.py . [ 95%]
tests/test_other.py . [ 97%]
tests/test_pie.py . [100%]
===================================================================================================================== 41 passed in 0.37s ======================================================================================================================
Building
Update the version
field in pyproject.toml
Create a git tag same as the version
uv build
uv publish --token pypi-YOURTOKENHERE
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pydacharts-0.2.0.tar.gz
(124.9 kB
view details)
Built Distribution
File details
Details for the file pydacharts-0.2.0.tar.gz
.
File metadata
- Download URL: pydacharts-0.2.0.tar.gz
- Upload date:
- Size: 124.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.4.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c26ca7033dd906c41e864b84b9769b2d45c749cf3f7f723bd5dbd51233ee91dd |
|
MD5 | 24e1b9c4edf6faf6fed2cdf19c4a0da5 |
|
BLAKE2b-256 | 732668547d0e317f2cb8857a7766715338b84aa761fae32399c58eca51d3ee80 |
File details
Details for the file pydacharts-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: pydacharts-0.2.0-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.4.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5242c29b41629fc74dd3fa3628b51a4869f86bde768a9aea5726f3138263b0d8 |
|
MD5 | 74bc862587833544abb2c438deb28442 |
|
BLAKE2b-256 | 57ee9c148d34b159cba7f1da553138a32ae5430a1cd6f84bd6445df5ca5861a8 |