Skip to main content

Cities Lookup is a simple tool for looking up city data. It returns the city name, population, and more.

Project description

Cities Lookup API

Cities Lookup is a simple tool for looking up city data. It returns the city name, population, and more.

Build Status Code Climate Prod Ready

This is a Python API Wrapper for the Cities Lookup API


Installation

Using pip:

pip install apiverve-citieslookup

Using pip3:

pip3 install apiverve-citieslookup

Configuration

Before using the citieslookup API client, you have to setup your account and obtain your API Key. You can get it by signing up at https://apiverve.com


Quick Start

Here's a simple example to get you started quickly:

from apiverve_citieslookup.apiClient import CitieslookupAPIClient

# Initialize the client with your APIVerve API key
api = CitieslookupAPIClient("[YOUR_API_KEY]")

query = {
    "city": "San Francisco",
    "limit": 1
}

try:
    # Make the API call
    result = api.execute(query)

    # Print the result
    print(result)
except Exception as e:
    print(f"Error: {e}")

Usage

The Cities Lookup API documentation is found here: https://docs.apiverve.com/ref/citieslookup. You can find parameters, example responses, and status codes documented here.

Setup

# Import the client module
from apiverve_citieslookup.apiClient import CitieslookupAPIClient

# Initialize the client with your APIVerve API key
api = CitieslookupAPIClient("[YOUR_API_KEY]")

Perform Request

Using the API client, you can perform requests to the API.

Define Query
query = {
    "city": "San Francisco",
    "limit": 1
}
Simple Request
# Make a request to the API
result = api.execute(query)

# Print the result
print(result)
Example Response
{
  "status": "ok",
  "error": null,
  "data": {
    "search": "San Francisco",
    "foundCities": [
      {
        "name": "San Francisco",
        "altName": "",
        "country": "US",
        "featureCode": "PPLA2",
        "population": 864816,
        "loc": {
          "type": "Point",
          "coordinates": [
            -122.41942,
            37.77493
          ]
        }
      },
      {
        "name": "San Francisco de Macorís",
        "altName": "",
        "country": "DO",
        "featureCode": "PPLA",
        "population": 124763,
        "loc": {
          "type": "Point",
          "coordinates": [
            -70.25259,
            19.30099
          ]
        }
      },
      {
        "name": "San Francisco del Rincón",
        "altName": "",
        "country": "MX",
        "featureCode": "PPLA2",
        "population": 71139,
        "loc": {
          "type": "Point",
          "coordinates": [
            -101.85515,
            21.01843
          ]
        }
      },
      {
        "name": "South San Francisco",
        "altName": "",
        "country": "US",
        "featureCode": "PPL",
        "population": 67271,
        "loc": {
          "type": "Point",
          "coordinates": [
            -122.40775,
            37.65466
          ]
        }
      },
      {
        "name": "San Francisco",
        "altName": "",
        "country": "AR",
        "featureCode": "PPLA2",
        "population": 59062,
        "loc": {
          "type": "Point",
          "coordinates": [
            -62.08266,
            -31.42797
          ]
        }
      },
      {
        "name": "San Francisco",
        "altName": "",
        "country": "CR",
        "featureCode": "PPL",
        "population": 55923,
        "loc": {
          "type": "Point",
          "coordinates": [
            -84.12934,
            9.99299
          ]
        }
      },
      {
        "name": "San Francisco El Alto",
        "altName": "",
        "country": "GT",
        "featureCode": "PPLA2",
        "population": 54493,
        "loc": {
          "type": "Point",
          "coordinates": [
            -91.4431,
            14.9449
          ]
        }
      },
      {
        "name": "San Francisco Acuautla",
        "altName": "",
        "country": "MX",
        "featureCode": "PPL",
        "population": 27960,
        "loc": {
          "type": "Point",
          "coordinates": [
            -98.86034,
            19.34564
          ]
        }
      },
      {
        "name": "San Francisco Cuaxusco",
        "altName": "",
        "country": "MX",
        "featureCode": "PPLX",
        "population": 24900,
        "loc": {
          "type": "Point",
          "coordinates": [
            -99.61925,
            19.26755
          ]
        }
      },
      {
        "name": "San Francisco Tlalcilalcalpan",
        "altName": "",
        "country": "MX",
        "featureCode": "PPL",
        "population": 16509,
        "loc": {
          "type": "Point",
          "coordinates": [
            -99.76771,
            19.29474
          ]
        }
      },
      {
        "name": "San Francisco",
        "altName": "",
        "country": "SV",
        "featureCode": "PPLA",
        "population": 16152,
        "loc": {
          "type": "Point",
          "coordinates": [
            -88.1,
            13.7
          ]
        }
      },
      {
        "name": "San Francisco de los Romo",
        "altName": "",
        "country": "MX",
        "featureCode": "PPLA2",
        "population": 16124,
        "loc": {
          "type": "Point",
          "coordinates": [
            -102.2714,
            22.07748
          ]
        }
      },
      {
        "name": "San Francisco Zapotitlán",
        "altName": "",
        "country": "GT",
        "featureCode": "PPLA2",
        "population": 13855,
        "loc": {
          "type": "Point",
          "coordinates": [
            -91.52144,
            14.58939
          ]
        }
      },
      {
        "name": "San Francisco Ocotlán",
        "altName": "",
        "country": "MX",
        "featureCode": "PPL",
        "population": 11636,
        "loc": {
          "type": "Point",
          "coordinates": [
            -98.28345,
            19.13411
          ]
        }
      },
      {
        "name": "San Francisco Tecoxpa",
        "altName": "",
        "country": "MX",
        "featureCode": "PPL",
        "population": 11456,
        "loc": {
          "type": "Point",
          "coordinates": [
            -99.00639,
            19.19167
          ]
        }
      },
      {
        "name": "San Francisco Telixtlahuaca",
        "altName": "",
        "country": "MX",
        "featureCode": "PPLA2",
        "population": 10618,
        "loc": {
          "type": "Point",
          "coordinates": [
            -96.90529,
            17.29684
          ]
        }
      },
      {
        "name": "San Francisco Tetlanohcan",
        "altName": "",
        "country": "MX",
        "featureCode": "PPLA2",
        "population": 9858,
        "loc": {
          "type": "Point",
          "coordinates": [
            -98.1637,
            19.2602
          ]
        }
      },
      {
        "name": "San Francisco Chimalpa",
        "altName": "",
        "country": "MX",
        "featureCode": "PPL",
        "population": 8953,
        "loc": {
          "type": "Point",
          "coordinates": [
            -99.34398,
            19.44279
          ]
        }
      },
      {
        "name": "Altos de San Francisco",
        "altName": "",
        "country": "PA",
        "featureCode": "PPL",
        "population": 8189,
        "loc": {
          "type": "Point",
          "coordinates": [
            -79.79,
            8.86167
          ]
        }
      },
      {
        "name": "San Francisco Zacacalco",
        "altName": "",
        "country": "MX",
        "featureCode": "PPL",
        "population": 7420,
        "loc": {
          "type": "Point",
          "coordinates": [
            -98.98279,
            19.92875
          ]
        }
      }
    ]
  }
}

Error Handling

The API client provides comprehensive error handling through the CitieslookupAPIClientError exception. Here are some examples:

Basic Error Handling

from apiverve_citieslookup.apiClient import CitieslookupAPIClient, CitieslookupAPIClientError

api = CitieslookupAPIClient("[YOUR_API_KEY]")

query = {
    "city": "San Francisco",
    "limit": 1
}

try:
    result = api.execute(query)
    print("Success!")
    print(result)
except CitieslookupAPIClientError as e:
    print(f"API Error: {e.message}")
    if e.status_code:
        print(f"Status Code: {e.status_code}")
    if e.response:
        print(f"Response: {e.response}")

Handling Specific Error Types

from apiverve_citieslookup.apiClient import CitieslookupAPIClient, CitieslookupAPIClientError

api = CitieslookupAPIClient("[YOUR_API_KEY]")

query = {
    "city": "San Francisco",
    "limit": 1
}

try:
    result = api.execute(query)

    # Check for successful response
    if result.get('status') == 'success':
        print("Request successful!")
        print(result.get('data'))
    else:
        print(f"API returned an error: {result.get('error')}")

except CitieslookupAPIClientError as e:
    # Handle API client errors
    if e.status_code == 401:
        print("Unauthorized: Invalid API key")
    elif e.status_code == 429:
        print("Rate limit exceeded")
    elif e.status_code >= 500:
        print("Server error - please try again later")
    else:
        print(f"API error: {e.message}")
except Exception as e:
    # Handle unexpected errors
    print(f"Unexpected error: {str(e)}")

Using Context Manager (Recommended)

The client supports the context manager protocol for automatic resource cleanup:

from apiverve_citieslookup.apiClient import CitieslookupAPIClient, CitieslookupAPIClientError

query = {
    "city": "San Francisco",
    "limit": 1
}

# Using context manager ensures proper cleanup
with CitieslookupAPIClient("[YOUR_API_KEY]") as api:
    try:
        result = api.execute(query)
        print(result)
    except CitieslookupAPIClientError as e:
        print(f"Error: {e.message}")
# Session is automatically closed here

Advanced Features

Debug Mode

Enable debug logging to see detailed request and response information:

from apiverve_citieslookup.apiClient import CitieslookupAPIClient

# Enable debug mode
api = CitieslookupAPIClient("[YOUR_API_KEY]", debug=True)

query = {
    "city": "San Francisco",
    "limit": 1
}

# Debug information will be printed to console
result = api.execute(query)

Manual Session Management

If you need to manually manage the session lifecycle:

from apiverve_citieslookup.apiClient import CitieslookupAPIClient

api = CitieslookupAPIClient("[YOUR_API_KEY]")

query = {
    "city": "San Francisco",
    "limit": 1
}

try:
    result = api.execute(query)
    print(result)
finally:
    # Manually close the session when done
    api.close()

Customer Support

Need any assistance? Get in touch with Customer Support.


Updates

Stay up to date by following @apiverveHQ on Twitter.


Legal

All usage of the APIVerve website, API, and services is subject to the APIVerve Terms of Service and all legal documents and agreements.


License

Licensed under the The MIT License (MIT)

Copyright (©) 2026 APIVerve, and EvlarSoft LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

apiverve_citieslookup-1.1.14.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

apiverve_citieslookup-1.1.14-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file apiverve_citieslookup-1.1.14.tar.gz.

File metadata

  • Download URL: apiverve_citieslookup-1.1.14.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.10

File hashes

Hashes for apiverve_citieslookup-1.1.14.tar.gz
Algorithm Hash digest
SHA256 98d613bde896fdbbbb5ca531be03a05ac265b5a0df571c50942b39998ee938a1
MD5 befb644fef4bc2d62fbf30f6248454eb
BLAKE2b-256 33b2737d1c56702e06f79a6be2a6775dab8c2bec0a8b871afeb95b1b919729b2

See more details on using hashes here.

File details

Details for the file apiverve_citieslookup-1.1.14-py3-none-any.whl.

File metadata

File hashes

Hashes for apiverve_citieslookup-1.1.14-py3-none-any.whl
Algorithm Hash digest
SHA256 5c7c3e62e23614583351f4df42278ab0596bff82bfb73dcf4ea9c4a143236e72
MD5 deba10aee093ef298f91bb1eaf5655e0
BLAKE2b-256 2ae69f48fa4e13818775200c10e6123f7942f873757496f5ccf67bacf7435575

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page