Simpler than you think: use Python to upload GIS layers to CartoDB

CartoDB has a nice dashboard you can use to upload shapefiles for viewing online. They have even included drag-and-drop functionality to help improve the experience. Nevertheless, uploading geographic files manually can be cumbersome and you can end up forgetting files sources, when you uploaded etc.

Fortunately, CartoDB recently posted a Python script that you can use to upload data directly to the dashboard from the command line. You can find a discussion of the file here but we thought we would demonstrate how to use it.

1. Download the python file

You can get the python file at GitHub. If you’re not familiar with GitHub it’s probably easiest to click on the ‘Raw’ button and then use your browser to save the script (called

2. Assemble the command line code to upload

The code you need to use to upload directly from the command line is fairly straightfoward. In this example, the Python script itself and the zipped shapefile are in the same directory. You will need the name of your account and an API key. If you don’t have an API key you would log into your account, in the top right click on your account name and you will see a dropdown menu with “Your API Keys” and follow the directions. Then the code looks like:

python import -f -k myAPIkey -u  myUSERNAME

On a Windows machine you will need to make sure that Python is part of your PATH otherwise you’ll need to specify the location of the Python executable.

Altogether this is a quick and easy way to upload and a good way to keep a record of the files you’re uploading to CartoDB.

Leave a Reply

Your email address will not be published. Required fields are marked *