Skip to main content

gmaps-boundary

Fetch the boundary polygon that Google Maps draws for a locality, city or postal code, as GeoJSON.

When you search for an area on Google Maps, the map outlines it with a red dotted line. This library reads that outline from the map's vector tiles and returns it as a polygon. It needs no API key and no browser.

Boundary of Indiranagar, Bengaluru, drawn over OpenStreetMap

Install

pip install gmaps-boundary

Python 3.10 or newer. Dependencies: httpx, shapely, numpy.

Use it

from gmaps_boundary import fetch_boundary

boundary = fetch_boundary("Indiranagar, Bengaluru")

boundary.place.name  # 'Indiranagar'
boundary.geometry  # shapely Polygon in WGS 84 (x = longitude, y = latitude)
boundary.bounds  # (west, south, east, north)
boundary.zoom  # 17
boundary.resolution_m  # 0.07, the size of one coordinate step in metres
boundary.to_geojson()  # GeoJSON Feature as a dict

fetch_boundary accepts any of these:

  • a place name: "Indiranagar, Bengaluru", "560038", "Manhattan, New York"
  • a full Google Maps place URL, the one that contains !1s0x...:0x...
  • a Place object, from find_place or built by hand

Boundary implements __geo_interface__, so GeoPandas and other libraries accept it directly:

import geopandas

frame = geopandas.GeoDataFrame.from_features([boundary.to_geojson()], crs="EPSG:4326")

Many places

Reuse one client. It keeps connections open and applies the same settings to every request.

from gmaps_boundary import BoundaryClient

with BoundaryClient(proxy="http://user:pass@host:8080", request_delay_s=0.2) as client:
    for name in ["Indiranagar, Bengaluru", "Koramangala, Bengaluru"]:
        boundary = client.fetch_boundary(name)

Your own HTTP session

Pass your own httpx.Client to control cookies, headers, proxies, timeouts and connection limits. The boundary client sends every request through it and never closes it.

import httpx
from gmaps_boundary import BoundaryClient

session = httpx.Client(
    headers={"User-Agent": "Mozilla/5.0 ..."},
    cookies={"NID": "..."},
    proxy="http://user:pass@host:8080",
    timeout=30.0,
)
with BoundaryClient(http_client=session) as client:
    boundary = client.fetch_boundary("Indiranagar, Bengaluru")
session.close()

AsyncBoundaryClient takes an httpx.AsyncClient the same way. Set a browser User-Agent on your session: Google answers the default httpx one differently. http_client cannot be combined with proxy, timeout_s, user_agent or transport; set those on the session.

Async

AsyncBoundaryClient fetches tiles concurrently. A locality takes about 6 seconds with concurrency=8, against about 25 seconds for the sync client.

import asyncio
from gmaps_boundary import AsyncBoundaryClient


async def main() -> None:
    async with AsyncBoundaryClient(concurrency=8) as client:
        boundary = await client.fetch_boundary("Koramangala, Bengaluru")


asyncio.run(main())

Command line

gmaps-boundary "Indiranagar, Bengaluru" -o indiranagar.geojson
gmaps-boundary "560038" --zoom 16 --indent 2 > pincode.geojson
gmaps-boundary "Manhattan, New York" -o manhattan.geojson --preview manhattan.png

--preview draws the boundary over an OpenStreetMap map and needs pip install 'gmaps-boundary[preview]'. Add --no-basemap to draw the outline alone, with no request to OpenStreetMap. Run gmaps-boundary --help for every option.

The same drawing is available from Python:

from gmaps_boundary.preview import save_preview

save_preview(boundary, "indiranagar.png")  # over OpenStreetMap
save_preview(boundary, "outline.png", basemap=False)  # outline only

The basemap uses at most 20 tiles from tile.openstreetmap.org per image. Map data (C) OpenStreetMap contributors.

Name lookup

A name goes to Google Maps search, and the library takes the place Google opens for it.

  • A name that matches nothing, or a category search such as "cafes in Indiranagar", raises PlaceNotFoundError.
  • An ambiguous name resolves to Google's top pick, which depends on the region of your IP address. "Springfield" can resolve to a landmark instead of a city. Add the city, state or country to the name, and check boundary.place.address.
  • A name that resolves to a place without a boundary, such as a shop or a road, raises NoBoundaryError.
  • To check a name before you fetch, call find_place(name). It makes one request and returns the Place.

Zoom and accuracy

Coordinates come from Google's tiles as integers, 4096 steps per tile side. A higher zoom means smaller steps and more vertices.

zoom step at the equator typical use
17 0.07 m localities, postal codes
15 0.30 m large districts
14 0.60 m cities
12 2.4 m regions

Zoom 17 is the finest zoom that carries boundaries. With zoom=None, the default, the library picks the finest zoom that fits max_tiles (default 500 tile requests per pass). Pass zoom= to fix it, or raise max_tiles for more detail on a large place.

For Indiranagar, the zoom 17 polygon has 214 vertices. Its bounds match the viewport Google Maps itself uses for the place to within 0.2 m.

Errors

Every error is a subclass of GmapsBoundaryError.

error meaning
PlaceNotFoundError The name matches no single place. Try a more specific name.
NoBoundaryError Google Maps draws no boundary for the place, for example a shop or a road.
TooManyTilesError The place does not fit max_tiles at the requested zoom.
ResponseFormatError A response had an unexpected shape. Google may have changed the format.
RequestFailedError A request failed after every retry.

How it works

  1. A name is resolved to a place through Google Maps search. This gives the feature id and the label point.
  2. Google Maps highlights a place through a vector tile layer named spotlit. Each tile carries a mask polygon that covers everything outside the place.
  3. The library reads the outline at a coarse zoom first. That pass sizes the job and tells the fine pass which tiles to fetch.
  4. For each fine tile, the place part is the tile square minus the mask. The parts are merged into one polygon and converted to longitude and latitude.

Limits

  • The tile and search formats are undocumented. Google can change them without notice. The library then raises ResponseFormatError instead of returning a wrong polygon.
  • A place made of separate pieces is returned as a MultiPolygon. A piece that lies more than about 10 km from the label point and does not touch the rest can be missed.
  • Short maps.app.goo.gl links are not accepted. Open the link and copy the full URL.
  • The boundary is what Google Maps displays. It is not an official administrative boundary.

Terms of use

This library is not affiliated with Google. It reads undocumented endpoints, which the Google Maps Platform Terms of Service do not permit for all uses. You are responsible for how you use it and for the data you collect. Keep the request rate low.

Development

uv sync
uv run pytest             # offline, replays recorded responses
uv run pytest -m live     # calls Google
uv run ruff check . && uv run ruff format --check . && uv run mypy
uv run python tests/record_fixtures.py   # refresh the recorded responses

License

MIT

Metadata

Release files for gmaps-boundary 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gmaps-boundary 0.1.0
File Size Uploaded Provenance Actions
gmaps_boundary-0.1.0.tar.gz 49.9 kB With provenance Details for gmaps_boundary-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gmaps-boundary 0.1.0
File Interpreter ABI Platform Actions
gmaps_boundary-0.1.0-py3-none-any.whl Python 3 none any Details for gmaps_boundary-0.1.0-py3-none-any.whl

Total release size: 74.2 kB

Release files / gmaps_boundary-0.1.0.tar.gz

Download URL gmaps_boundary-0.1.0.tar.gz
Size 49.9 kB
Tags Source
SHA-256 checksum
How to use checksums
9050dd33bddda03603d7371499e040a8f85c3fe833f2537cc08fa121696779da
BLAKE2b-256 checksum
How to use checksums
ff0baa148375951b01879f0144617b95699665e4ddd612f1d61c7f7978c6bbbe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Release files / gmaps_boundary-0.1.0-py3-none-any.whl

Download URL gmaps_boundary-0.1.0-py3-none-any.whl
Size 24.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
06b89946f39db0acd98fad3ee30e0f9f2347c22ea13d5f4cdfc0f72b78b1212f
BLAKE2b-256 checksum
How to use checksums
e5ad4dfa498a65bc51865d3badbdbefc517fde31e30527f2c5343ed1aaf6c4b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Security for gmaps-boundary 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for gmaps_boundary-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page