bharat-choropleth
bharat-choropleth creates dependency-free, accessible static SVG
choropleths from TopoJSON. It is a Python sibling to the repository’s React,
plain-JavaScript, and Flutter renderers, intended for reports, generated web
pages, and notebooks that should not need a browser or JavaScript runtime.
It includes no boundaries. Pass a mapping or path to your own TopoJSON and
retain the source attribution and licence for any boundary bundle you use.
The repository’s prepared bundles are under data/generated
and their notices are documented in data/ATTRIBUTION.md.
Install
pip install bharat-choropleth
# Only when you need a Matplotlib axes rather than SVG:
pip install 'bharat-choropleth[matplotlib]'
# Only when you need interactive state-to-district controls in Jupyter:
pip install 'bharat-choropleth[notebook]'
Generate an SVG
from bharat_choropleth import render_svg
values = {
"in-cs-30-goa": 6,
"in-cs-24-gujarat": 7,
"in-cs-27-maharashtra": 41,
}
svg = render_svg(
"data/generated/current-2019-states/states.topo.json",
values,
object_name="states",
title="Example state metric",
description="A static map. Regions without a supplied value are marked as no data.",
)
open("states.svg", "w", encoding="utf-8").write(svg)
render_svg returns a complete <svg> element with a title, optional
description, per-region accessible labels, an even-odd fill rule, and a
lower-to-higher legend. Features with missing, invalid, or non-finite values
receive the distinct no-data colour; they are never treated as low values.
Decode once, render repeatedly
from bharat_choropleth import decode_topology, render_svg
states = decode_topology("states.topo.json", object_name="states")
svg = render_svg(states, {"in-cs-30-goa": 6})
The decoder understands TopoJSON’s quantized delta arcs, reversed arc indexes, holes, polygons, and multi-polygons. Every part is retained—an archipelago is rendered as separate islands, never as a fabricated enclosing polygon.
Optional Matplotlib
from bharat_choropleth.matplotlib import render_matplotlib
ax = render_matplotlib("states.topo.json", values, object_name="states")
ax.figure.savefig("states.png", dpi=180, bbox_inches="tight")
The Matplotlib adapter is an extra, so importing bharat_choropleth does not
pull in Matplotlib or any other rendering dependency.
Jupyter drill-down
Install the notebook extra for an ipywidgets state selector and lazy
district loader. The control updates its inline SVG when a state is selected;
it has no browser-map or JavaScript runtime dependency.
from pathlib import Path
from bharat_choropleth.notebook import notebook_drilldown
root = Path.cwd()
states = root / "data/generated/current-2019-states/states.topo.json"
district_dir = root / "data/generated/current-2019-districts/districts"
map_control = notebook_drilldown(
states,
{"in-cs-30-goa": 6, "in-cs-31-lakshadweep": 43},
district_loader=lambda state_id: district_dir / f"{state_id}.topo.json",
states_object_name="states",
)
map_control.widget # Display this as the last Jupyter cell expression.
Pass district_values as either a {state_id: {district_id: value}} mapping
or a state_id -> {district_id: value} callable to colour the district view.
API
| Item | Purpose |
|---|---|
load_topology(source) |
Load a TopoJSON mapping or JSON file path. |
decode_topology(source, object_name=...) |
Decode Polygon/MultiPolygon areas into immutable Feature objects. |
ColorScale.fit(values) |
Fit the shared low-to-high colour ramp to finite values. |
render_svg(source, values, ...) |
Create a complete static, accessible SVG string. |
bharat_choropleth.matplotlib.render_matplotlib(...) |
Optional static Matplotlib renderer. |
bharat_choropleth.notebook.notebook_drilldown(...) |
Optional ipywidgets state-to-district SVG control. |
Develop and package
python -m unittest discover -s tests -v
python -m build
twine check dist/*
Publishing to PyPI is intentionally a separate, identity-bound action:
python -m twine upload --repository testpypi dist/* # optional first check
python -m twine upload dist/*
Never commit a PyPI token or generated third-party boundary data without first checking its redistribution conditions.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bharat_choropleth-0.1.0.tar.gz.
File metadata
- Download URL: bharat_choropleth-0.1.0.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7236bcbc3bd4d3661c9b27babcf5f524e4970c206375984e9635de86fa2e12c2
|
|
| MD5 |
213c41bc7e4b71e275147e509a985f78
|
|
| BLAKE2b-256 |
7dfa04516531390747b8f1148bce41aa565a91a43a77bd605f9c8170c2a1b708
|
File details
Details for the file bharat_choropleth-0.1.0-py3-none-any.whl.
File metadata
- Download URL: bharat_choropleth-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
014e35a8ccc3530a89dabc7b7f95deb0a0990c2e43c7d5b388292ce3892b2c46
|
|
| MD5 |
6cb2f89de8406598881223f874d39c00
|
|
| BLAKE2b-256 |
b73624f50e8a156a0aec2b28ada89cffad064f3a433ae9c66a79a6f268fd59d1
|