Share a Folium map
A Folium map is one of the friendliest things Python can produce and one of
the least shareable. m.save("map.html") writes a working Leaflet app; then
it sits in a working directory, and the person who needs it gets a screenshot
of the map at exactly one zoom level — which is to say, none of the map.
Publish it
import folium, requests, os
from folium.plugins import MarkerCluster
m = folium.Map(location=[40.71, -74.01], zoom_start=11)
cluster = MarkerCluster().add_to(m)
for row in sites.itertuples():
folium.Marker([row.lat, row.lon], popup=row.name).add_to(cluster)
m.save("map.html")
requests.post(
"https://commareports.com/api/v1/reports",
headers={"Authorization": f"Bearer {os.environ['COMMA_API_TOKEN']}"},
json={"title": "Service coverage — NYC", "html": open("map.html").read()},
).raise_for_status()
Folium's generated file pulls Leaflet and its plugins from jsdelivr and cdnjs — both allowlisted for scripts inside report HTML — and tiles are plain image requests, allowed from any HTTPS origin. So the published map pans, zooms, clusters and pops exactly like the local one.
What the URL changes
- The reviewer explores instead of squinting. Zoom to their own borough, check their own site.
- Comments pin to context. Wrap the map in a short brief — what changed, what decision is pending — and the discussion anchors to that text. See commenting on HTML.
- A map per week, one URL. PATCH the same report id and coverage drift becomes a revision history instead of a folder of dated files.
Keep the key quiet
If you use a paid tile provider, the token is embedded in the tile URL — that is true of any static Leaflet export. Publish with a domain-restricted key, and keep the report private or team-visible; see the sharing model. Reports are private by default.
Limits
- HTML body: 5 MB. Cluster or aggregate before saving; raw marker arrays are the usual culprit.
- Scripts run, sandboxed:
allow-scripts, noallow-same-origin. - 60 requests/minute per token.
Try it
Comma is free — unlimited reports, unlimited commenters, unlimited revision history.