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
- Fork it (https://github.com/Jonchun/allcities/fork)
- Create your feature branch (
git checkout -b feature/fooBar) - Commit your changes (
git commit -am 'Add some fooBar') - Push to the branch (
git push origin feature/fooBar) - Create a new Pull Request
Metadata
Release files for allcities 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| allcities-1.0.3.tar.gz | 7.2 kB | Without provenance | Details for allcities-1.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| allcities-1.0.3-py3-none-any.whl | Python 3 | none | any | Details for allcities-1.0.3-py3-none-any.whl |
Total release size: 16.5 MB
Release files / allcities-1.0.3.tar.gz
| Download URL | allcities-1.0.3.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
76240a091bca8e2ab505247eefa23b30ae1c19f023503d228921f03841a090a6
|
|
BLAKE2b-256 checksum How to use checksums |
86b77cca12415bc2a682e5b2cbe4dc7b16df3485c5262de14e6cada33624eeb9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / allcities-1.0.3-py3-none-any.whl
| Download URL | allcities-1.0.3-py3-none-any.whl |
|---|---|
| Size | 16.5 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4f2628c00a0ad3d61980bafe7a6b682b341bdaae2945ba6a0749a676c5108b73
|
|
BLAKE2b-256 checksum How to use checksums |
50c87da067bc638794bf9d3c6d748d8f3f048c241f8a71a53cee92f1732f10e8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for allcities 1.0.3
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.