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.