{"record":{"id":"a756e1abe66a419d","repo":"pola-rs/polars","slug":"fsspec-is-required-for-storage-options-argumen","errorCode":null,"errorMessage":"`fsspec` is required for `storage_options` argument","messagePattern":"`fsspec` is required for `storage_options` argument","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/_utils.py","lineNumber":169,"sourceCode":"    An http URL is read into a buffer and returned as a `BytesIO`.\n\n    When `encoding` is not `utf8` or `utf8-lossy`, the whole file is\n    first read in Python and decoded using the specified encoding and\n    returned as a `BytesIO` (for usage with `read_csv`). If encoding\n    ends with \"-lossy\", characters that can't be decoded are replaced\n    with `�`.\n\n    A `bytes` file is returned as a `BytesIO` if `use_pyarrow=True`.\n\n    When fsspec is installed, remote file(s) is (are) opened with\n    `fsspec.open(file, **kwargs)` or `fsspec.open_files(file, **kwargs)`.\n    If encoding is not `utf8` or `utf8-lossy`, decoding is handled by\n    fsspec too.\n    \"\"\"\n    storage_options = storage_options.copy() if storage_options else {}\n    if storage_options and not _FSSPEC_AVAILABLE:\n        msg = \"`fsspec` is required for `storage_options` argument\"\n        raise ImportError(msg)\n\n    # Small helper to use a variable as context\n    @contextmanager\n    def managed_file(file: Any) -> Iterator[Any]:\n        try:\n            yield file\n        finally:\n            pass\n\n    has_utf8_utf8_lossy_encoding = (\n        encoding in {\"utf8\", \"utf8-lossy\"} if encoding else True\n    )\n    encoding_str = encoding if encoding else \"utf8\"\n    encoding_str, encoding_errors = (\n        (encoding_str[:-6], \"replace\")\n        if encoding_str.endswith(\"-lossy\")\n        else (encoding_str, \"strict\")\n    )","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/io/_utils.py#L151-L187","documentation":"Polars raises this ImportError in prepare_file_arg when a caller passes `storage_options` but the optional `fsspec` package is not installed. storage_options are only meaningful for fsspec-handled sources (remote URLs, cloud filesystems), so without fsspec there is no way to apply them.","triggerScenarios":"Calling pl.read_csv/read_parquet/etc. (or scan_ variants that route through prepare_file_arg) with storage_options={...} set while fsspec is absent from the environment.","commonSituations":"Reading from S3/GCS/Azure/HTTP in a fresh environment; CI containers with a slim polars install; code copied from a notebook that had fsspec installed; a dependency bump that dropped the extra `polars[fsspec]`.","solutions":["Install fsspec: pip install fsspec (or pip install 'polars[fsspec]').","Install the filesystem-specific companion (e.g. s3fs, gcsfs, adlfs) alongside fsspec.","If the source is local and storage_options were passed by mistake, remove the storage_options argument."],"exampleFix":"// before\n df = pl.read_csv(\"s3://bucket/file.csv\", storage_options={\"key\": k, \"secret\": s})\n// after\n # pip install fsspec s3fs\n df = pl.read_csv(\"s3://bucket/file.csv\", storage_options={\"key\": k, \"secret\": s})","handlingStrategy":"validation","validationCode":"import importlib.util\nif storage_options and importlib.util.find_spec('fsspec') is None:\n    raise RuntimeError('fsspec is required when passing storage_options')","typeGuard":"def fsspec_available() -> bool:\n    return importlib.util.find_spec('fsspec') is not None","tryCatchPattern":"try:\n    df = pl.read_csv(url, storage_options=opts)\nexcept ImportError as e:\n    if 'fsspec' in str(e):\n        raise SystemExit(\"Install fsspec: pip install 'polars[fsspec]'\") from e\n    raise","preventionTips":["Pin dependencies with an extra: 'polars[fsspec]' in requirements/pyproject.","Check find_spec('fsspec') at app startup when remote IO is a feature.","Only pass storage_options for remote/fsspec-backed URLs."],"tags":["python","io","missing-dependency","fsspec"],"backgroundTag":"missing-optional-dependency","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}