Skip to main content

allcities - Python library to access all the cities of the world with a population of at least 1000 inhabitants.

Project description

allcities

a Python library to work with all the cities of the world with a population of at least 1000 inhabitants.

Note

This library was whipped up in an afternoon when I got a little carried away when I really needed something much simpler. It is not fully tested and will need revisiting/cleanup.

Installation

pip install allcities

Usage example

Usage of this library is quite simple.

from allcities import cities

results = cities.filter(name='Los Angeles')
for result in results:
    print(result)

cities is a set-like object that contains objects that represent cities. The above code will output:

<Santa Rosa los Angeles, 11, MX>
<Los Angeles, 10, MX>
<Los Angeles, CA, US>
<Los Angeles, 25, MX>
<Lake Los Angeles, CA, US>
<East Los Angeles, CA, US>
<Los Angeles, 13, PH>

You can chain/combine filters as follows:

results = cities.filter(name='Los Angeles').filter(country_code='US')
results2 = cities.filter(name='Los Angeles', country_code='US')
print(results == results2)
for result in results:
    print(result)

gives you

True
<Los Angeles, CA, US>
<East Los Angeles, CA, US>
<Lake Los Angeles, CA, US>

You can also filter on numeric properties. The syntax to do so is a comparison operator <, <=, ==, !=, >=, > followed by a numeric value.

results = cities.filter(elevation='>1000')
results2 = cities.filter(elevation='>1000').filter(elevation='<1500')
print(results)
print(results2)

Gives you

<CitySet (1339)>
<CitySet (795)>

Each city object has properties that can be accessed normally or filtered on. You can also export a dictionary with the .dict property.

pprint.pprint(city_object.dict)

Here is the resulting dict

{'admin1_code': 'CA',
 'admin2_code': '037',
 'alternatenames': ['East Los Angeles',
                    'Este de Los Angeles',
                    'Este de Los Ángeles',
                    'Ist Los Andzeles',
                    'Orienta Losangeleso',
                    'Orienta Losanĝeleso',
                    'dong luo shan ji',
                    'iseuteuloseuaenjelleseu',
                    'ista lasa enjelsa',
                    'isutorosanzerusu',
                    'Ист Лос Анџелес',
                    'इस्ट लस एन्जेल्स',
                    'イーストロサンゼルス',
                    '东洛杉矶',
                    '이스트로스앤젤레스'],
 'asciiname': 'East Los Angeles',
 'country_code': 'US',
 'dem': 63,
 'elevation': 61,
 'feature_class': 'P',
 'feature_code': 'PPL',
 'geonameid': 5344994,
 'latitude': 34.0239,
 'longitude': -118.17202,
 'modification_date': '2011-05-14',
 'name': 'East Los Angeles',
 'population': 126496,
 'timezone': 'America/Los_Angeles'}

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Release History

  • 1.0.0
    • Initial Release

Contributing

  1. Fork it (https://github.com/Jonchun/allcities/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

Project details


Download files

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

Source Distribution

allcities-1.0.3.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

allcities-1.0.3-py3-none-any.whl (16.5 MB view details)

Uploaded Python 3

File details

Details for the file allcities-1.0.3.tar.gz.

File metadata

  • Download URL: allcities-1.0.3.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for allcities-1.0.3.tar.gz
Algorithm Hash digest
SHA256 76240a091bca8e2ab505247eefa23b30ae1c19f023503d228921f03841a090a6
MD5 8a6aa2e543bf62983e0e7a8e72177d3b
BLAKE2b-256 86b77cca12415bc2a682e5b2cbe4dc7b16df3485c5262de14e6cada33624eeb9

See more details on using hashes here.

File details

Details for the file allcities-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: allcities-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 16.5 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for allcities-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4f2628c00a0ad3d61980bafe7a6b682b341bdaae2945ba6a0749a676c5108b73
MD5 da25df4ba9feece78ad634b1fd622a12
BLAKE2b-256 50c87da067bc638794bf9d3c6d748d8f3f048c241f8a71a53cee92f1732f10e8

See more details on using hashes here.

Supported by

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