> ## Documentation Index
> Fetch the complete documentation index at: https://nixtla-old-docs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Datasets Utils

***

<a href="https://github.com/Nixtla/datasetsforecast/blob/main/datasetsforecast/utils.py#L33" target="_blank" style={{ float: "right", fontSize: "smaller" }}>source</a>

### download\_file

> ```text theme={null}
>  download_file (directory:str, source_url:str, decompress:bool=False)
> ```

*Download data from source\_ulr inside directory.*

***

<a href="https://github.com/Nixtla/datasetsforecast/blob/main/datasetsforecast/utils.py#L21" target="_blank" style={{ float: "right", fontSize: "smaller" }}>source</a>

### extract\_file

> ```text theme={null}
>  extract_file (filepath, directory)
> ```

***

<a href="https://github.com/Nixtla/datasetsforecast/blob/main/datasetsforecast/utils.py#L90" target="_blank" style={{ float: "right", fontSize: "smaller" }}>source</a>

### async\_download\_files

> ```text theme={null}
>  async_download_files (path:Union[str,pathlib.Path], urls:Iterable[str])
> ```

```python theme={null}
import os
import tempfile

import requests
```

```python theme={null}
gh_url = 'https://api.github.com/repos/Nixtla/datasetsforecast/contents/'
base_url = 'https://raw.githubusercontent.com/Nixtla/datasetsforecast/main'

headers = {}
gh_token = os.getenv('GITHUB_TOKEN')
if gh_token is not None:
    headers = {'Authorization': f'Bearer: {gh_token}'}
resp = requests.get(gh_url, headers=headers)
if resp.status_code != 200:
    raise Exception(resp.text)
urls = [f'{base_url}/{e["path"]}' for e in resp.json() if e['type'] == 'file']
with tempfile.TemporaryDirectory() as tmp:
    tmp = Path(tmp)
    await async_download_files(tmp, urls)
    files = list(tmp.iterdir())
    assert len(files) == len(urls)
```

***

<a href="https://github.com/Nixtla/datasetsforecast/blob/main/datasetsforecast/utils.py#L102" target="_blank" style={{ float: "right", fontSize: "smaller" }}>source</a>

### download\_files

> ```text theme={null}
>  download_files (directory:Union[str,pathlib.Path], urls:Iterable[str])
> ```

```python theme={null}
with tempfile.TemporaryDirectory() as tmp:
    tmp = Path(tmp)
    fname = tmp / 'script.py'
    fname.write_text(f"""
from datasetsforecast.utils import download_files
    
download_files('{tmp.as_posix()}', {urls})
    """)
    !python {fname}
    fname.unlink()
    files = list(tmp.iterdir())
    assert len(files) == len(urls)
```

***

<a href="https://github.com/Nixtla/datasetsforecast/blob/main/datasetsforecast/utils.py#L113" target="_blank" style={{ float: "right", fontSize: "smaller" }}>source</a>

### Info

> ```text theme={null}
>  Info (class_groups:Tuple[dataclass])
> ```

*Info Dataclass of datasets. Args: groups (Tuple): Tuple of str groups
class\_groups (Tuple): Tuple of dataclasses.*
