diff --git a/README.md b/README.md
index b164037..80a9d4e 100644
--- a/README.md
+++ b/README.md
@@ -63,4 +63,18 @@ train_images = mnist.train_images()
 x = images.reshape((images.shape[0], images.shape[1] * images.shape[2]))
 ```
 
+Both the url where the files can be found, and the temporary directory where
+they will be cached locally can be modified in the next way:
+```
+import mnist
+
+mnist.datasets_url = 'http://url-to-the/datasets'
+
+# temporary_dir is a function, so it can be dinamically created
+# like Python stdlib `tempfile.gettempdir` (which is the default)
+mnist.temporary_dir = lambda: '/tmp/mnist'
+
+train_images = mnist.train_images()
+```
+
 It supports Python 2.7 and Python >= 3.5.
diff --git a/mnist/__init__.py b/mnist/__init__.py
index 2a41398..a567875 100644
--- a/mnist/__init__.py
+++ b/mnist/__init__.py
@@ -16,8 +16,11 @@ except ImportError:
 import numpy
 
 
-# the url can be changed by the users of the library (not a constant)
+# `datasets_url` and `temporary_dir` can be set by the user using:
+# >>> mnist.datasets_url = 'http://my.mnist.url'
+# >>> mnist.temporary_dir = lambda: '/tmp/mnist'
 datasets_url = 'http://yann.lecun.com/exdb/mnist/'
+temporary_dir = tempfile.gettempdir
 
 
 class IdxDecodeError(ValueError):
@@ -45,8 +48,7 @@ def download_file(fname, target_dir=None, force=False):
     fname : str
         Full path of the downloaded file
     """
-    if not target_dir:
-        target_dir = tempfile.gettempdir()
+    target_dir = target_dir or temporary_dir()
     target_fname = os.path.join(target_dir, fname)
 
     if force or not os.path.isfile(target_fname):

diff --git a/tests/test_download_mnist.py b/tests/test_download_mnist.py
index 631104d..e71aabe 100644
--- a/tests/test_download_mnist.py
+++ b/tests/test_download_mnist.py
@@ -97,8 +97,20 @@ class TestDownloadMNIST(unittest.TestCase):
 
     @mock.patch('mnist.urlretrieve')
     def test_datasets_url_is_used(self, urlretrieve):
+        original_url = mnist.datasets_url
         mnist.datasets_url = 'http://aaa.com/'
         mnist.download_file('mnist_datasets_url.gz')
         fname = os.path.join(tempfile.gettempdir(), 'mnist_datasets_url.gz')
         urlretrieve.assert_called_once_with(
             'http://aaa.com/mnist_datasets_url.gz', fname)
+        mnist.datasets_url = original_url
+
+    @mock.patch('mnist.urlretrieve')
+    def test_temporary_dir_is_used(self, urlretrieve):
+        original_temp_dir = mnist.temporary_dir
+        mnist.temporary_dir = lambda: '/another/tmp/dir/'
+        fname = mnist.download_file('test')
+        urlretrieve.assert_called_once_with(mnist.datasets_url + 'test',
+                                            '/another/tmp/dir/test')
+        self.assertEqual(fname, '/another/tmp/dir/test')
+        mnist.temporary_dir = original_temp_dir

Allowing specification of the download directory
Right now the functions listed on the README.md doesn't allow specifying the target directory. This functionality should be possible just by propagating extra parameters to the download function.
tests/test_download_mnist.py::TestDownloadMNIST::test_temporary_dir_is_used
tests/test_download_mnist.py::TestDownloadMNIST::test_datasets_url_is_used tests/test_download_mnist.py::TestDownloadMNIST::test_file_is_downloaded_to_target_dir tests/test_download_mnist.py::TestDownloadMNIST::test_file_is_downloaded_when_exists_and_force_is_true tests/test_download_mnist.py::TestDownloadMNIST::test_file_is_not_downloaded_when_force_is_false