Repository: apify/crawlee-python
File: src/crawlee/storages/_dataset.py (Python)

Code before:

    Args:
        ensure_asci: Whether non-ASCII characters should be escaped in the output JSON string.
        indent: Specifies the number of spaces to use for indentation in the pretty-printed JSON output.
        sort_keys: Specifies whether the output JSON object should have its keys sorted alphabetically.
    """

    ensure_asci: NotRequired[bool]
    indent: NotRequired[int]
    sort_keys: NotRequired[bool]


class ExportDataCsvKwargs(TypedDict):
    """Keyword arguments for dataset's `export_data_csv` method.

    Args:
        delimiter: A character that separates fields in the CSV file.
        quotechar: A character used to enclose fields containing special characters like the delimiter.
        quoting: An integer that defines how quotes should be applied.
    """

    delimiter: NotRequired[str]
    quotechar: NotRequired[str]
    quoting: NotRequired[int]


class Dataset(BaseStorage):
    """Represents an append-only structured storage, ideal for tabular data similar to database tables.

    The `Dataset` class is designed to store structured data, where each entry (row) maintains consistent attributes
    (columns) across the dataset. It operates in an append-only mode, allowing new records to be added, but not
    modified or deleted. This makes it particularly useful for storing results from web crawling operations.

    Data can be stored either locally or in the cloud. It depends on the setup of underlying storage client.
    By default a `MemoryStorageClient` is used, but it can be changed to a different one.

    By default, data is stored using the following path structure:
    ```
    {CRAWLEE_STORAGE_DIR}/datasets/{DATASET_ID}/{INDEX}.json
    ```
    - `{CRAWLEE_STORAGE_DIR}`: The root directory for all storage data specified by the environment variable.
    - `{DATASET_ID}`: Specifies the dataset, either "default" or a custom dataset ID.
    - `{INDEX}`: Represents the zero-based index of the record within the dataset.

    To open a dataset, use the `open` class method by specifying an `id`, `name`, or `configuration`. If none are
    provided, the default dataset for the current crawler run is used. Attempting to open a dataset by `id` that does
    not exist will raise an error; however, if accessed by `name`, the dataset will be created if it doesn't already
    exist.

    Usage:
    ```python

Review comment (suggestion):
We avoid using `TypedDict` for additional kwargs when passing them to third-party functions, as we don't have control over the interface. So please use just `**kwargs: Any` instead.

Code after:
    """Name of the key-value store to save the exported file."""


class ExportDataJsonKwargs(TypedDict):
    """Keyword arguments for dataset's `export_data_json` method.

    Args:
        skipkeys: If True (default: False), then dict keys that are not of a basic type (str, int, float, bool, None)
            will be skipped instead of raising a TypeError.
        ensure_ascii: Whether non-ASCII characters should be escaped in the output JSON string.
        check_circular: If False (default: True), then the circular reference check for container types will be skipped
            and a circular reference will result in a RecursionError (or worse).
        allow_nan: If False (default: True), then it will be a ValueError to serialize out of range float values
            (nan, inf, -inf) in strict compliance of the JSON specification. If allow_nan is true, their JavaScript
            equivalents (NaN, Infinity, -Infinity) will be used.
        cls: Allows using a custom JSON encoder
        indent: Specifies the number of spaces to use for indentation in the pretty-printed JSON output.
            separators: a (item_separator, key_separator) tuple. The default is (', ', ': ') if indent is None
            and (',', ': ') otherwise.
        default: A function that gets called for objects that can't otherwise be serialized.
            It should return a JSON encodable version of the object or raise a TypeError.
        sort_keys: Specifies whether the output JSON object should have its keys sorted alphabetically.
    """

    skipkeys: NotRequired[bool]
    ensure_ascii: NotRequired[bool]
    check_circular: NotRequired[bool]
    allow_nan: NotRequired[bool]
    cls: NotRequired[type[json.JSONEncoder]]
    indent: NotRequired[int]
    separators: NotRequired[tuple[str, str]]
    default: NotRequired[Callable]
    sort_keys: NotRequired[bool]


class ExportDataCsvKwargs(TypedDict):
    r"""Keyword arguments for dataset's `export_data_csv` method.

    Args:
        delimiter: A one-character string used to separate fields. It defaults to ','.
        doublequote: Controls how instances of quotechar appearing inside a field should themselves be quoted.
            When True, the character is doubled. When False, the escapechar is used as a prefix to the quotechar.
            It defaults to True.
        escapechar: A one-character string used by the writer to escape the delimiter if quoting is set to QUOTE_NONE
            and the quotechar if doublequote is False. On reading, the escapechar removes any special meaning from
            the following character. It defaults to None, which disables escaping.
        lineterminator: The string used to terminate lines produced by the writer. It defaults to '\r\n'.
        quotechar: A one-character string used to quote fields containing special characters, such as the delimiter or
            quotechar, or which contain new-line characters. It defaults to '"'.
        quoting: Controls when quotes should be generated by the writer and recognised by the reader.
            It can take on any of the QUOTE_* constants and defaults to QUOTE_MINIMAL.