closecity
This is the Python software development kit for the Close.City API. It returns travel times from every US census block to nearby places, on foot, by bike, and by public transit. The data behind close.city is served over the Close API.
Documentation: https://henryspatialanalysis.github.io/closecity-python/
Install
Will soon be on PyPI; install from GitHub until then:
pip install git+https://github.com/henryspatialanalysis/closecity-python.git
# add the census-block boundary downloader:
pip install "closecity[tiger] @ git+https://github.com/henryspatialanalysis/closecity-python.git"
This pulls in httpx, pandas, and geopandas, so results come back as data
frames out of the box: a GeoDataFrame where geometry applies, a plain DataFrame
otherwise.
A first call
You make requests through a client. Routes with geometry come back as GeoDataFrames, so you can map them right away.
from closecity import Client, close_map
# The key (ck_live_) comes from https://account.close.city (5,000 free tokens
# on signup, no card). You can also set the CLOSECITY_KEY environment variable
# and call Client() with no argument.
close = Client("ck_live_your_key") # use your own key here
# Supermarkets within a 1.5 km walk of a point (type 30 is grocery stores):
supermarkets = close.pois_search(lat = 41.823, lon = -71.412, radius_m = 1500, type = 30)
close_map(supermarkets, color = "#e8590c") # interactive map, bright hoverable points
Catalog and lookup routes are free, need no key, and come back as data frames:
close = Client()
close.modes() # walk, bike, transit
close.places("Providence") # a city name to its GEOID and centre
Key terms
A few terms come up throughout the API:
- Census block. The smallest area the Census Bureau publishes. Each one has a 15-digit id called a GEOID.
- Destination type. A category of place, such as grocery stores or libraries.
Each type has a numeric id. Look them up with
close.destination_types(). - Mode. How someone travels: walk, bike, or transit.
- Isochrone or catchment: the area you can reach starting from a point within a time limit, by a selected travel mode.
Choose an output
Set output on the client, or per call:
output = "spatial"(the default) returns a GeoDataFrame for inherently spatial data and a DataFrame otherwise. Block routes join census-block boundaries withpygris(thetigerextra), downloaded once and cached.output = "tabular"returns a plain DataFrame for every route and never downloads boundaries. Reach for it when you only want the numbers.output = "raw"returns the underlyingReply/Paginator, with the parsed body on.dataand the token counts alongside.
close = Client("ck_live_your_key", output = "raw") # use your own key here
for poi in close.pois_search(lat = 41.823, lon = -71.412, radius_m = 1500):
print(poi["name"])
Handling errors
Problem responses become typed exceptions. Catch a specific one, or the
CloseAPIError base.
from closecity import TokensExhaustedError, CloseAPIError
try:
close.block_summary("000000000000000")
except TokensExhaustedError:
...
except CloseAPIError as err:
print(err.status, err.slug)
The client does not retry automatically. On a RateLimitedError or
ServiceUnavailableError, wait err.retry_after seconds (from the
Retry-After header) and retry the request yourself.
Reference
- Documentation: https://henryspatialanalysis.github.io/closecity-python/
- Interactive API: https://api.close.city/docs
- Machine-readable contract: https://api.close.city/openapi.json
Development
pip install -e '.[dev]'
pytest # unit tests, no network (httpx MockTransport)
ruff check src tests
Metadata
Release files for closecity 1.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| closecity-1.5.0.tar.gz | 31.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| closecity-1.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 54.9 kB
Release files / closecity-1.5.0.tar.gz
| Download URL | closecity-1.5.0.tar.gz |
|---|---|
| Size | 31.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
86b069a3d7980a494da34a9ab17d5e50f02ace0553348438f62439edf03226eb
|
|
BLAKE2b-256 checksum How to use checksums |
3ab7211c650a6f7d9755d18a224cd9a05437b934c4d5ace532a4b5c89ee25fa1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
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 Jul 23, 2026.
Transparency logRelease files / closecity-1.5.0-py3-none-any.whl
| Download URL | closecity-1.5.0-py3-none-any.whl |
|---|---|
| Size | 23.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1311431c7628ea3851379b4c37810ed6a962260dc4f296db35df9071f995349c
|
|
BLAKE2b-256 checksum How to use checksums |
f3017873dc8e792c1d9e343ff8459f5a7ebd51bb03c414fe5c6f70bf5cdf3577
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
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 Jul 23, 2026.
Transparency log