Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a .csv file containing financial data which is generated on a regular basis outside QGIS. Then I want to create a PyQGIS script that will add the .csv file as a layer in my project. (The idea here is I want to have the up-to-date financial data as attributes data for one of the shapefiles in the project). Is there a way to run the script automatically as soon as I open the QGIS project. Thank you

share|improve this question
Why not store the layer as a view in a database, and use your csv creation script to instead import the data to table as part of the view, the other part being the spatial component? – wildintellect Mar 17 '14 at 17:32

Put your script in .qgis/python/ and it should run when QGIS is opened. However, this will run with any project you open, which you may not want.

So you might be better off setting up a python macro in the specific project. File > Project properties > Macros. Enable macrcos by checking the box.

def openProject():
    wack your code here!

def saveProject():

def closeProject():
share|improve this answer
+1 Marcos are the way to go. If you have a lot of code I would suggest putting it in it's own .py file next to the project and importing it from openProject rather then putting lots of logic in the blocks. Makes it easier to test and debug. – Nathan W Mar 17 '14 at 10:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.