Location · 4 min read
How to use the Cities & Countries API in Python & JavaScript
Location lookups should be one call, not a dataset to host. Here's how to do it with the Cities & Countries API.
By DataNest · Published May 2026
What the Cities & Countries API does
A worldwide geographic database: city search with population filters, full country profiles (capital, borders, currencies, timezones), and regions. Responses are JSON, the API runs behind the RapidAPI gateway for auth and rate limiting, and there's a free tier for prototyping.
When to use it
The example request
GET https://cities-countries-by-datanest.p.rapidapi.com/cities?minPopulation=10000000Example JSON response
An illustrative response body — run the live demo for the real thing.
{
"count": 1,
"cities": [
{
"name": "Mumbai",
"country": "India",
"region": "Maharashtra",
"population": 12442373,
"latitude": 19.07283,
"longitude": 72.88261,
"timezone": "Asia/Kolkata"
}
]
}Common parameters
Every request also needs your RapidAPI auth headers.
| Parameter | In | Required | Example |
|---|---|---|---|
| limit | query | No | 5 |
| minPopulation | query | Yes | 10000000 |
| x-rapidapi-key | header | Yes | YOUR_RAPIDAPI_KEY |
| x-rapidapi-host | header | Yes | cities-countries-by-datanest.p.rapidapi.com |
Step by step
1. Subscribe and get your key
Open the Cities & Countries API on RapidAPI, subscribe to the free BASIC plan, and copy your X-RapidAPI-Key.
2. Call the endpoint
The example call for this API is shown above. The quick-start snippets below send exactly that request in cURL, Python and Node so you get a real response on the first try.
3. Try it without code first
The Cities & Countries page has a live "Try it" panel — change the input, run it, and inspect the real JSON before you integrate.
4. Integrate and cache
Call it from your backend and cache responses where it makes sense. Most responses change slowly, so even a daily cache keeps you well within the free tier.
Quick-start code
curl --request GET \
--url 'https://cities-countries-by-datanest.p.rapidapi.com/cities?limit=5&minPopulation=10000000' \
--header 'x-rapidapi-host: cities-countries-by-datanest.p.rapidapi.com' \
--header 'x-rapidapi-key: YOUR_RAPIDAPI_KEY'What you can build
Location autocomplete
Power a city dropdown that resolves to region and country.
Shipping validator
Confirm a destination city exists before checkout.
Demographic explorer
Compare cities by population and geography in a research tool.
Wrapping up
If your project needs location autocomplete, the Cities & Countries API removes the part nobody enjoys building. It's one of 23 in the DataNest collection — grab a free key and make your first call.
Share this guide
Related guides
How to use the Pincode API in Python & JavaScript
155,000+ Indian PIN codes — post office, district, state & delivery status lookup.
How to use the Crypto Intelligence API in Python & JavaScript
Real-time crypto trading signals — BUY/SELL/HOLD based on RSI, MACD & trend analysis.
How to use the Stock Market API in Python & JavaScript
Real-time quotes, analyst ratings, earnings & market movers for 50,000+ tickers.
Cities & Countries updates
New Cities & Countries guides and endpoint updates, occasionally.