Skip to main content
https://secure.travis-ci.org/yourlabs/django-cities-light.svg?branch=master https://img.shields.io/pypi/dm/django-cities-light.svg https://img.shields.io/pypi/v/django-cities-light.svg https://codecov.io/github/yourlabs/django-cities-light/coverage.svg

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.

Requirements:

  • Python >= 3.8

  • Django >= 3.2

  • 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.

Features

  • GraphQL support

  • Built-in admin support

  • Rest-Framework support

  • Ajax Select Lookup support

Upgrade

See CHANGELOG.

Installation

Install django-cities-light:

pip install django-cities-light

Or the development version:

pip install -e git+git@github.com:yourlabs/django-cities-light.git#egg=cities_light

Add cities_light to your INSTALLED_APPS.

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

CITIES_LIGHT_TRANSLATION_LANGUAGES = ['fr', 'en']
CITIES_LIGHT_INCLUDE_COUNTRIES = ['FR']
CITIES_LIGHT_INCLUDE_CITY_TYPES = ['PPL', 'PPLA', 'PPLA2', 'PPLA3', 'PPLA4', 'PPLC', 'PPLF', 'PPLG', 'PPLL', 'PPLR', 'PPLS', 'STLMT',]

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

./manage.py migrate

Data import/update

Finally, populate your database with command:

./manage.py cities_light

This command is well documented, consult the help with:

./manage.py 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:

./manage.py cities_light --keep-slugs

Get more cities

The configuration parameter CITIES_LIGHT_CITY_SOURCES, comes with the default value http://download.geonames.org/export/dump/cities15000.zip 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: http://download.geonames.org/export/dump/readme.txt

Using fixtures

Geonames.org 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:

./manage.py cities_light_fixtures dump
./manage.py 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:

./manage.py help cities_light_fixtures

Development

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

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

To run the test project, with the folder of the project as the current directory, run:

export PYTHONPATH="${PYTHONPATH}:/app/src"
docker run  -d postgres -p 5432:5432

Then run the full import:

test_project/manage.py migrate
test_project/manage.py cities_light

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

For example to change the database engine, you can run:

export DB_ENGINE=postgresql
export DB_HOST=192.168.0.118
export DB_NAME=app
export DB_USER=postgres
export DB_PORT=5432

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:

tox

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

tox -e py312-django42-sqlite

And to run one specific test use this one:

tox -e py312-django42-sqlite -- cities_light/tests/test_form.py::FormTestCase::testCountryFormNameAndContinentAlone

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

source .tox/py312-django42-sqlite/bin/activate
CI=true test_project/manage.py 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

TODOS

Resources

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

Metadata

Release files for django-cities-light 3.10.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-cities-light 3.10.2
File Size Uploaded
django_cities_light-3.10.2.tar.gz 106.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-cities-light 3.10.2
File Interpreter ABI Platform
django_cities_light-3.10.2-py3-none-any.whl Python 3 none any Details

Total release size: 231.0 kB

Release files / django_cities_light-3.10.2.tar.gz

Download URL django_cities_light-3.10.2.tar.gz
Size 106.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4f4473affb3376a3e52b791b9347845d849ed876b26fac0b980edc765692aa86
BLAKE2b-256 checksum
How to use checksums
2c959f126c3852054b6f8cfb99c6bfaa103279c327a72c85313ef5c2469d856f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / django_cities_light-3.10.2-py3-none-any.whl

Download URL django_cities_light-3.10.2-py3-none-any.whl
Size 124.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
28ca79d954ea5e4771fc42f8a9235e0501ba482ef1b7d647035d186f18198aad
BLAKE2b-256 checksum
How to use checksums
ed2f19aa98982d1b85d15aabc15ff273e5ecd27542c2d3ca59f22dff9fb741de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release history Release notifications | RSS feed

3.11

2 release files

This release

3.10.2 This release

2 release files

3.10.0

2 release files

3.9.2

2 release files

3.9.1

2 release files

3.9.0

2 release files

3.8.1

2 release files

3.8.0

2 release files

3.7.0

1 release file

3.6.0

1 release file

3.5.1

1 release file

3.5.0

1 release file

3.4.0

1 release file

3.3.0

1 release file

3.2.0

1 release file

3.1.2

1 release file

3.1.0

1 release file

3.0.5

1 release file

3.0.4

1 release file

3.0.3

1 release file

3.0.2

1 release file

3.0.1

1 release file

3.0.0

1 release file

2.4.3

1 release file

2.4.2

1 release file

2.4.1

1 release file

2.4.0

1 release file

2.3.1

1 release file

2.3.0

1 release file

2.1.13

1 release file

2.1.12

1 release file

2.1.11

1 release file

2.1.10

1 release file

2.1.9

1 release file

2.1.8

1 release file

2.1.7

1 release file

2.1.6

1 release file

2.1.5

1 release file

2.1.4

1 release file

2.1.3

1 release file

2.1.2

1 release file

2.1.1

1 release file

2.1.0

1 release file

2.0.9

1 release file

2.0.8

1 release file

2.0.7

1 release file

2.0.6

1 release file

2.0.5

1 release file

2.0.4

1 release file

2.0.2

1 release file

2.0.1

1 release file

2.0.0

1 release file

1.9.4

1 release file

1.9.3

1 release file

1.9.2

1 release file

1.9.1

1 release file

1.9.0

1 release file

1.8

1 release file

1.7

1 release file

1.5.1

1 release file

1.5

1 release file

1.4

1 release file

1.3

1 release file

1.2

1 release file

1.1

1 release file

1.0

1 release file

0.19

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page