Skip to main content
https://secure.travis-ci.org/yourlabs/django-cities-light.png?branch=master https://pypip.in/d/django-cities-light/badge.png https://pypip.in/v/django-cities-light/badge.png https://codecov.io/github/yourlabs/django-cities-light/coverage.svg?branch=stable/3.x.x

django-cities-light – Simple django-cities alternative

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

The data is pulled from GeoNames and contains cities, 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 2.7 or 3.3,

  • Django >= 1.8

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

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/City slugs. But there is an option to keep them intact:

./manage.py cities_light --keep-slugs

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

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.

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 py27-django18-sqlite

And to run one specific test use this one:

tox -e py27-django18-sqlite -- cities_light/tests/test_form.py::FormTestCase::testCountryFormNameAndContinentAlone

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

source .tox/py27-django18-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

If you are ready to send a patch, please read YourLabs guidelines: https://github.com/yourlabs/community/blob/master/docs/guidelines.rst

Resources

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

Metadata

Release files for olivia-django-cities-light 1.0.0

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

Source distribution (sdist)

Source distribution for olivia-django-cities-light 1.0.0
File Size Uploaded Provenance Actions
olivia-django-cities-light-1.0.0.tar.gz 35.4 kB Without provenance Details for olivia-django-cities-light-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for olivia-django-cities-light 1.0.0
File Interpreter ABI Platform Actions
olivia_django_cities_light-1.0.0-py2-none-any.whl Python 2 none any Details for olivia_django_cities_light-1.0.0-py2-none-any.whl

Total release size: 80.8 kB

Release files / olivia-django-cities-light-1.0.0.tar.gz

Download URL olivia-django-cities-light-1.0.0.tar.gz
Size 35.4 kB
Tags Source
SHA-256 checksum
How to use checksums
acaf868391e7f573cbd89ce4f29ae6c088eb89ff7a228cacc3da92b99ab58cea
BLAKE2b-256 checksum
How to use checksums
2437b419e3acc1740747a735621f412bfaba67d35e0dc521a22888561cafd4e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.6.9

Release files / olivia_django_cities_light-1.0.0-py2-none-any.whl

Download URL olivia_django_cities_light-1.0.0-py2-none-any.whl
Size 45.4 kB
Tags Python 2
SHA-256 checksum
How to use checksums
41929995c175136e03591e38b4dba29918651f30968b4ff071d01f4f4b6c3f09
BLAKE2b-256 checksum
How to use checksums
247f33d0a2cf48493b71e565db5ba222788ba48b06b1a8ee947fc50980dcacbe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.6.9

Security for olivia-django-cities-light 1.0.0

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.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

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