---
sidebar:
  hidden: true
title: roboto.formats.parquet.fetch
---
## Module Contents

### logger

```python
roboto.formats.parquet.fetch.logger
```

`from roboto.formats.parquet.fetch import logger`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/parquet/fetch.py#L25-L25)

### open_parquet_file()

```python
def roboto.formats.parquet.fetch.open_parquet_file(
    url_provider: Callable[[], str],
    cache_outfile: Optional[pathlib.Path],
    policy: roboto.storage.cache.CachePolicy,
    estimated_column_count: int,
    size_bytes: Optional[int] = None,
) -> pyarrow.parquet.ParquetFile
```

`from roboto.formats.parquet import open_parquet_file`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/parquet/fetch.py#L90-L144)

Open a remote Parquet file from the local cache, a new download to it, or HTTP, as a cache policy selects.

[`choose_fetch_mode()`](/docs/reference/python-sdk/roboto/storage/cache#roboto.storage.cache.choose_fetch_mode) selects one of three sources:

1. A copy already at `cache_outfile`, read without a request.
2. A copy downloaded to `cache_outfile` by [`download_to_cache()`](/docs/reference/python-sdk/roboto/storage/cache#roboto.storage.cache.download_to_cache), which never leaves a partial file there.
3. The remote file, read over HTTP by `parquet_file_from_url` without writing to disk.

**Parameters**

- **url_provider** (`Callable[[], str]`): Function that returns a signed URL for the file. Called at most once, and only when the file is downloaded or read over HTTP.
- **cache_outfile** (`Optional[pathlib.Path]`): Local cache path of the file. `None` reads the file over HTTP, whatever `policy` says.
- **policy** (`roboto.storage.cache.CachePolicy`): Cache policy of the read.
- **estimated_column_count** (`int`): Number of columns the read is expected to need. Under [`ADAPTIVE`](/docs/reference/python-sdk/roboto/storage/cache#roboto.storage.cache.CachePolicy.ADAPTIVE), it decides between downloading the file and reading it over HTTP.
- **size_bytes** (`Optional[int]`): Size of the remote file in bytes, as Roboto reports it. `None` when unknown, which accepts a cached copy of any size and skips the downloaded file's size check. When given, a cached copy of a different size is not read, and a size of at least 16 MiB skips the first request of `parquet_file_from_url`.

**Raises**

- `ValueError`: The downloaded file's size differs from `size_bytes`, or the file read over HTTP is empty.
- `urllib.error.URLError`: The download request fails.
- `ImportError`: The `roboto[analytics]` extra is not installed.

**Returns**

- `pyarrow.parquet.ParquetFile`

### parquet_file_from_url()

```python
def roboto.formats.parquet.fetch.parquet_file_from_url(
    signed_url: str,
    size_bytes: Optional[int] = None,
) -> pyarrow.parquet.ParquetFile
```

`from roboto.formats.parquet import parquet_file_from_url`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/parquet/fetch.py#L31-L87)

Open a Parquet file from a signed URL, reading it over HTTP without writing it to disk.

The file is read in one of two ways:

1. Unless `size_bytes` is at least 16 MiB, one request fetches the file's first 16 MiB. When fewer bytes come back, that is the whole file, and it is read from memory with no further request.
2. When `size_bytes` is at least 16 MiB, or the first request returns 16 MiB or fails, the file is read with HTTP range requests, each fetching only the bytes a read needs.

**Parameters**

- **signed_url** (`str`): Signed URL of the file, such as one [`get_signed_url()`](/docs/reference/python-sdk/roboto/domain/files/file#roboto.domain.files.file.File.get_signed_url) returns.
- **size_bytes** (`Optional[int]`): Size of the file in bytes. `None` when unknown. A size of at least 16 MiB skips the first request, which could not return the whole file.

**Raises**

- `ValueError`: The first request succeeds but returns no bytes: the file is empty, so it is not a Parquet file.
- `ImportError`: The `roboto[analytics]` extra is not installed.

**Returns**

- `pyarrow.parquet.ParquetFile`
