Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Extract and count countries and cities (+their synonyms) from text

Project description

Build Status Coverage

flashgeotext :zap::earth_africa:

Extract and count countries and cities (+their synonyms) from text, like GeoText on steroids using FlashText, a Aho-Corasick implementation. Flashgeotext is a fast, batteries-included (and BYOD) and native python library that extracts one or more sets of given city and country names (+ synonyms) from an input text.



from flashgeotext.geotext import GeoText

geotext = GeoText(use_demo_data=True)

input_text = '''Shanghai. The Chinese Ministry of Finance in Shanghai said that China plans
                to cut tariffs on $75 billion worth of goods that the country
                imports from the US. Washington welcomes the decision.'''

geotext.extract(input_text=input_text, span_info=True)
>> {
    'cities': {
        'Shanghai': {
            'count': 2,
            'span_info': [(0, 8), (45, 53)]
        'Washington, D.C.': {
            'count': 1,
            'span_info': [(175, 185)]
    'countries': {
        'China': {
            'count': 1,
            'span_info': [(64, 69)]
        'United States': {
            'count': 1,
            'span_info': [(171, 173)]

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.


for usage:

pip install flashgeotext

for development:

git clone
pip install flit
flit install

Running the tests

pytest flashgeotext/tests -v


  • Benjamin Ramser - Initial work - iwpnd

See also the list of contributors who participated in this project.


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

Demo Data cities from licensed under the Creative Commons Attribution 3.0 License.


Project details

Download files

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

Files for flashgeotext, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size flashgeotext-0.1.0-py3-none-any.whl (434.4 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size flashgeotext-0.1.0.tar.gz (680.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page