|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/datasets/blob/v4.9.10/tensorflow_datasets/core/naming.py#L486-L703) |

Template to produce filenames for sharded datasets.

    tfds.core.ShardedFileTemplate(
        data_dir: epath.Path,
        template: str = DEFAULT_FILENAME_TEMPLATE,
        dataset_name: (str | None) = None,
        split: (str | None) = None,
        filetype_suffix: (str | None) = None
    )

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `data_dir` | the directory that contains the files for the shards. |
| `template` | template of the sharded files, e.g. '\\({SPLIT}/data.\\){FILEFORMAT}-${SHARD_INDEX}'. |
| `dataset_name` | the name of the dataset. |
| `split` | the split of the dataset. |
| `filetype_suffix` | the filetype suffix to denote the type of file. For example, `tfrecord`. |
| `regex` | Returns the regular expression for this template. <br /> Can be used to test whether a filename matches to this template. |

<br />

## Methods

### `filepath_prefix`

[View source](https://github.com/tensorflow/datasets/blob/v4.9.10/tensorflow_datasets/core/naming.py#L649-L655)

    filepath_prefix() -> str

Returns the path of the data shards without the shard suffix.

### `glob_pattern`

[View source](https://github.com/tensorflow/datasets/blob/v4.9.10/tensorflow_datasets/core/naming.py#L687-L696)

    glob_pattern(
        num_shards: (int | None) = None
    ) -> str

Returns a glob pattern for all the file paths captured by this template.

### `is_valid`

[View source](https://github.com/tensorflow/datasets/blob/v4.9.10/tensorflow_datasets/core/naming.py#L565-L591)

    is_valid(
        filename: str
    ) -> bool

Returns whether the given filename follows this template.

### `parse_filename_info`

[View source](https://github.com/tensorflow/datasets/blob/v4.9.10/tensorflow_datasets/core/naming.py#L530-L563)

    parse_filename_info(
        filename: str
    ) -> (FilenameInfo | None)

Parses the filename using this template.

Note that when the filename doesn't specify the dataset name, split, or
filetype suffix, but this template does, then the value in the template will
be used.

<br />

<br />

<br />

| Arguments ||
|---|---|
| `filename` | the filename that should be parsed. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| the FilenameInfo corresponding to the given file if it could be parsed. None otherwise. ||

<br />

### `relative_filepath`

[View source](https://github.com/tensorflow/datasets/blob/v4.9.10/tensorflow_datasets/core/naming.py#L603-L627)

    relative_filepath(
        *, shard_index: int, num_shards: (int | None)
    ) -> str

Returns the path (relative to the data dir) of the shard.

### `replace`

[View source](https://github.com/tensorflow/datasets/blob/v4.9.10/tensorflow_datasets/core/naming.py#L701-L703)

    replace(
        **kwargs
    ) -> 'ShardedFileTemplate'

Returns a copy of the `ShardedFileTemplate` with updated attributes.

### `sharded_filenames`

[View source](https://github.com/tensorflow/datasets/blob/v4.9.10/tensorflow_datasets/core/naming.py#L698-L699)

    sharded_filenames(
        num_shards: int
    ) -> list[str]

### `sharded_filepath`

[View source](https://github.com/tensorflow/datasets/blob/v4.9.10/tensorflow_datasets/core/naming.py#L629-L638)

    sharded_filepath(
        *, shard_index: int, num_shards: (int | None)
    ) -> epath.Path

Returns the filename (including full path if `data_dir` is set) for the given shard.

### `sharded_filepaths`

[View source](https://github.com/tensorflow/datasets/blob/v4.9.10/tensorflow_datasets/core/naming.py#L640-L647)

    sharded_filepaths(
        num_shards: int
    ) -> list[epath.Path]

### `sharded_filepaths_pattern`

[View source](https://github.com/tensorflow/datasets/blob/v4.9.10/tensorflow_datasets/core/naming.py#L657-L685)

    sharded_filepaths_pattern(
        *, num_shards: (int | None) = None, use_at_notation: bool = False
    ) -> str

Returns a pattern describing all the file paths captured by this template.

If `num_shards` is given, then it returns
`/path/dataset_name-split.fileformat@num_shards` or
`/path/dataset_name-split@num_shards.fileformat` depending on the format.
If `num_shards` is not given, then it returns
`/path/dataset_name-split.fileformat-[0-9][0-9][0-9][0-9][0-9]-of-[0-9][0-9][0-9][0-9][0-9]`.

<br />

<br />

<br />

| Args ||
|---|---|
| `num_shards` | optional specification of the number of shards. |
| `use_at_notation` | whether to return @\* in case `num_shards` is `None`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| the pattern describing all shards captured by this template. ||

<br />

### `__eq__`

    __eq__(
        other
    )

Return self==value.

<br />

<br />

<br />

| ## Class Variables ||
|---|---|
| dataset_name | `None` |
| filetype_suffix | `None` |
| split | `None` |
| template | `'{DATASET}-{SPLIT}.{FILEFORMAT}-{SHARD_X_OF_Y}'` |

<br />