Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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 am developing an app for the Ubuntu App Showdown 2012, say "myapp". It needs to download files from the web, store them temporarily and then read them. Where should I save those files ? Now I do it in /tmp/myapp/, so this path is "hard coded" in my code.

Would the answer to my question be changed if I also need to modify/write into those temporary files ?

share|improve this question
up vote 4 down vote accepted

I reckon you want to use the xdg module - in fact, I think this is suggested in at least one of the app showdown workshops.

The xdg module provides a means to get a base path for where certain files should be stored.

So, for temporary files, ~/.cache seems like a good bet.

$XDG_CACHE_HOME defines the base directory relative to which user specific non-essential data files should be stored. If $XDG_CACHE_HOME is either not set or empty, a default equal to $HOME/.cache should be used.


import xdg.BaseDirectory
import os

temp_path = os.path.join(xdg.BaseDirectory.xdg_cache_home, 'app_name', 'downloads')
print temp_path
share|improve this answer

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.