geonames-tagger
This library finds the names of places in a string of text and tries to associate them with known locations from geonames.org. The goal is to tag a piece (or set) of text with mentioned locations, optionally to refine location names to a more canonized value. As well, the corresponding geoname IDs are returned in a tagging result.
As opposed to the original countrytagger, this library doesn't ship with the data included, so one needs to build it first and then point the GEONAMES_PLACES env var at the built places.tsv. Thanks to anystore, this can be a local path (the default: ./geonames.db/places.tsv) or any remote uri, e.g. s3://mybucket/places.tsv or https://example.org/places.tsv.
Data
Usage of the GeoNames data is licensed under a Creative Commons Attribution 4.0 License. Please verify that usage complies with your project.
Install
pip install geonames-tagger
Usage
cli
echo "I just visited Sant Julia de loria last week" | geonames-tagger tag
this results in the following json response:
{
"name": "sant julia de loria",
"caption": [
"Sant Julià de Lòria"
],
"id": [
3039162,
3039163
]
}
Input and output are uris handled by anystore, so -i / -o accept local paths, s3://, http(s):// or - for stdin/stdout (the default).
By default, duplicate matches are aggregated: each location is emitted once per input, no matter how many lines mention it. Use --no-aggregate to stream one result per match instead:
geonames-tagger tag -i report.txt --no-aggregate
python
from geonames_tagger import tag_locations
text = "I am in Berlin"
for result in tag_locations(text):
print(result.name) # the normalized name found in the text
print(result.caption) # the canonical names as list from GeoNames db
print(result.id) # the GeoNames IDs as list
Building the data
You can (re-)generate the places database like this:
geonames-tagger build
This will download the full GeoNames dump (allCountries.zip, ~400 MB) and parse it into the format used by this library, written to $GEONAMES_PLACES (default: ./geonames.db/places.tsv).
Use -i to build from an already downloaded dump and -o to override the output uri:
geonames-tagger build -i ./allCountries.zip -o s3://mybucket/places.tsv
During the build, name variants that would produce noisy matches are dropped: very short alternate spellings (tune via GEONAMES_MIN_ALTERNATE_LENGTH, default 6), numeric codes, and names that are common dictionary words in major languages (unless the place is big enough to be meant anyway, like Berlin or China). At tagging time, matches that are part of a person's name (e.g. "Heinrich XIII") are suppressed as well.
License and Copyright
geonames-tagger, (C) 2025 Data and Research Center – DARC
geonames-tagger is licensed under the AGPLv3 or later license.
The original countrytagger is released under the MIT license.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file geonames_tagger-1.1.0.tar.gz.
File metadata
- Download URL: geonames_tagger-1.1.0.tar.gz
- Upload date:
- Size: 20.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
poetry/2.4.1 CPython/3.14.6 Linux/7.0.10+deb14-amd64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a182b0dee65c578a7abdebc8309bb007a9d8c7c2d7e6647c136242e1848a34e7
|
|
| MD5 |
f16b2659fb04dbb9a784fd688729c348
|
|
| BLAKE2b-256 |
38e0aa8f381a3c87cf7778f58df8788aafe03c1156b60d0ec4aa0cfd0d799b2c
|
File details
Details for the file geonames_tagger-1.1.0-py3-none-any.whl.
File metadata
- Download URL: geonames_tagger-1.1.0-py3-none-any.whl
- Upload date:
- Size: 23.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
poetry/2.4.1 CPython/3.14.6 Linux/7.0.10+deb14-amd64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4295a434b0e61dcf28a2dcefce25402d095706c248a8e5591009fe40a18b14d6
|
|
| MD5 |
7edc82edcf0e637c13e9c41f066d1ea2
|
|
| BLAKE2b-256 |
d586c14fd4ff55fafee784f2fbf60157019a8b4d0c6b99ad25912b6271522dfd
|