Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
This branch is 695 commits ahead, 226 commits behind coderholic:master.

Latest commit

* django 4.1 and python 3.11

* django 4.1 and python 3.11

* check qa

Co-authored-by: marianoeramirez <Sosinformatico1990>

Git stats


Failed to load latest commit information.

django-cities-light -- Simple django-cities alternative

This add-on provides models and commands to import country, subregion, region/state, and city data in your database.

The data is pulled from GeoNames and contains cities, subregions, regions/states and countries.

Spatial query support is not required by this application.

This application is very simple and is useful if you want to make a simple address book for example. If you intend to build a fully featured spatial database, you should use django-cities.


  • Python >= 3.8
  • Django >= 3.0
  • MySQL or PostgreSQL or SQLite.

Yes, for some reason, code that used to work on MySQL (not without pain xD) does not work anymore. So we're now using django.db.transaction.atomic which comes from Django 1.6 just to support MySQL quacks.




Install django-cities-light:

pip install django-cities-light

Or the development version:

pip install -e

Add cities_light to your INSTALLED_APPS.

Configure filters to exclude data you don't want, ie.:


Now, run migrations, it will only create tables for models that are not disabled:

./ migrate

Data import/update

Finally, populate your database with command:

./ cities_light

This command is well documented, consult the help with:

./ help cities_light

By default, update procedure attempts to update all fields, including Country/Region/Subregion/City slugs. But there is an option to keep them intact:

./ cities_light --keep-slugs

Get more cities

The configuration parameter CITIES_LIGHT_CITY_SOURCES, comes with the default value that has cities with a population over 15000, if you need to load cities with less population please use another source. For the list of available source please check here:

Using fixtures is updated on daily basis and its full import is quite slow, so if you want to import the same data multiple times (for example on different servers) it is convenient to use fixtures with the helper management command:

./ cities_light_fixtures dump
./ cities_light_fixtures load

To reduce space, JSON fixtures are compressed with bzip2 and can be fetched from any HTTP server or local filesystem.

Consult the help with:

./ help cities_light_fixtures


Create development virtualenv (you need to have tox installed in your base system):

tox -e dev
source .tox/dev/bin/activate

Then run the full import:

test_project/ migrate
test_project/ cities_light

There are several environment variables which affect project settings (like DB_ENGINE and CI), you can find them all in test_project/

To run the test suite you need to have postgresql or mysql installed with passwordless login, or just use sqlite. Otherwise the tests which try to create/drop database will fail.

Running the full test suite:


To run the tests in specific environment use the following command:

tox -e py37-django31-sqlite

And to run one specific test use this one:

tox -e py37-django31-sqlite -- cities_light/tests/

To run it even faster, you can switch to specific tox virtualenv:

source .tox/py37-django18-sqlite/bin/activate
CI=true test_project/ test cities_light.tests.test_form.FormTestCase.testCountryFormNameAndContinentAlone

If you want to build the docs, use the following steps:

source .tox/dev/bin/activate
cd docs
make html


You could subscribe to the mailing list ask questions or just be informed of package updates.


A simple app providing three models: Country, Region and City model. Also provided, a command to insert or update data from geonames database dumps. Status: stable.







No packages published


  • Python 100.0%