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):

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.
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

pip install -e .
parse_log_pytest
numpy
pytest
apt-get update apt-get install -y gcc
3.9
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
exceptiongroup==1.2.2
iniconfig==2.1.0
-e git+https://github.com/datapythonista/mnist.git@aeae1406afea11c1c23788f23856053edcfc536b#egg=mnist
numpy @ file:///croot/numpy_and_numpy_base_1736283260865/work/dist/numpy-2.0.2-cp39-cp39-linux_x86_64.whl#sha256=3387e3e62932fa288bc18e8f445ce19e998b418a65ed2064dd40a054f976a6c7
packaging==24.2
pluggy==1.5.0
pytest==8.3.5
tomli==2.2.1

name: mnist
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - blas=1.0=openblas
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgfortran-ng=11.2.0=h00389a5_1
  - libgfortran5=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libopenblas=0.3.21=h043d6bf_0
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - numpy=2.0.2=py39heeff2f4_0
  - numpy-base=2.0.2=py39h8a23956_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=72.1.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - exceptiongroup==1.2.2
      - iniconfig==2.1.0
      - packaging==24.2
      - pluggy==1.5.0
      - pytest==8.3.5
      - tomli==2.2.1
prefix: /opt/conda/envs/mnist

tests/test_download_mnist.py::TestDownloadMNIST::test_temporary_dir_is_used
tests/test_download_mnist.py::TestDownloadMNIST::test_test_images_has_right_size tests/test_download_mnist.py::TestDownloadMNIST::test_test_labels_has_right_size tests/test_download_mnist.py::TestDownloadMNIST::test_train_images_has_right_size tests/test_download_mnist.py::TestDownloadMNIST::test_train_labels_has_right_size
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
mnist/__init__.py README.md
mnist/__init__.py README.md