Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Given the name of a comuna in Chile, it returns its code

Project Description


Very simple package that, given the name of a comuna from Chile, returns its code


Each comuna in Chile has a unique code that makes easier to map them to different attributes (e.g. choropleth). Since I was going through the hassle of doing it each time I had a new project, I decided to build a very simple tool that could automate the task. I hope this can be of use to other developers / civic-hackers.

I added a fuzzy version for cases where there was no exact match.


  • Given a comuna name, it returns its code, taking care of special characters, uppercases and lowercases.
  • If it doesn’t find an exact match, it prints that and returns None
  • A fuzzy function returns the best match (uses fuzzywuzzy)
  • You can specify to print the score of the fuzzy match
  • You can specify a threshold above which it should return a match and below which it shouldn’t.
  • There is a function that tries the exact match and if it doesn’t find it, it goes to the fuzzy version.
  • The list of comunas-code is a simple CSV file for easier edition.
  • If you want some comuna name version added to the csv file, just contact me and I’ll add them right away.


pip3 install clcomuna


  • fuzzywuzzy
  • Python3.3+


>>> import clcomuna

(If there is a warning, ignore it. It comes with the dependency)


>>> clcomuna.get_code("peumo")

get_fuzzy: returns name, not code

>>> clcomuna.get_fuzzy("alragobo")
>>> clcomuna.get_fuzzy("alragobo", True)
>>> clcomuna.get_fuzzy("alragobo", True, 72)
Score lower than minimum threshold for comuna: ALRAGOBO - ALGARROBO

The optional second parameter True prints the found comuna and the score. The optional third parameter int stablishes a threshold for the function to return the best name match


>>> clcomuna.get_steps("alragobo")
Could not find code for:  ALRAGOBO
>>> clcomuna.get_steps("alragobo", False, 74)
Score lower than minimum threshold for comuna: ALRAGOBO - ALGARROBO
Release History

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
clcomuna-1.1.3.tar.gz (6.5 kB) Copy SHA256 Checksum SHA256 Source Jul 4, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting