|
| 1 | +# Python integration reference |
| 2 | + |
| 3 | +Public names are exported from `fsspec_python` unless stated otherwise. |
| 4 | + |
| 5 | +## Importers |
| 6 | + |
| 7 | +### `install_importer(fs, **kwargs)` |
| 8 | + |
| 9 | +Accepts a URL string or `AbstractFileSystem`. For an instance, `fo` supplies the |
| 10 | +module root. A URL already supplies its root; passing `fo` with a string raises |
| 11 | +`AssertionError`. Other input types raise `TypeError`. |
| 12 | + |
| 13 | +Returns the installed `PythonFileSystem`. Repeated installation of the same normalized root reuses its importer. |
| 14 | +New finders are inserted at the front of `sys.meta_path`. |
| 15 | + |
| 16 | +### `uninstall_importer(fs="")` |
| 17 | + |
| 18 | +Accepts the original URL or returned filesystem. An empty argument removes the |
| 19 | +last installed importer. With no installed importers, it does nothing. An unknown |
| 20 | +root raises `ValueError` when other importers remain installed. |
| 21 | + |
| 22 | +Removal deletes the finder's tracked module names from `sys.modules` and removes |
| 23 | +the finder from `sys.meta_path`. Existing references to module objects remain valid. |
| 24 | + |
| 25 | +### `PythonFileSystem(target_protocol=None, target_options=None, fs=None, install=True, **kwargs)` |
| 26 | + |
| 27 | +Chained filesystem with protocol `python`. Exactly one of `target_protocol` and |
| 28 | +`fs` is required. `target_options` configures a newly constructed target; `fo` sets |
| 29 | +the source root for an unchained target. `install=False` suppresses automatic |
| 30 | +importer registration. `exit()` removes the importer and calls the target's |
| 31 | +`exit()` when available. |
| 32 | + |
| 33 | +### `FSSpecImportFinder` and `FSSpecImportLoader` |
| 34 | + |
| 35 | +The finder checks the configured root for the final component of a module name |
| 36 | +plus a Python source suffix. Matches have `is_package=False`. Package directories, |
| 37 | +namespace packages, native extensions, and normal package-relative search are not |
| 38 | +implemented. The loader reads source bytes with the filesystem's `open`. |
| 39 | + |
| 40 | +## Open hook |
| 41 | + |
| 42 | +### `install_open_hook(fsspec, **fsspec_args)` |
| 43 | + |
| 44 | +Resolves a root URL with fsspec and replaces `builtins.open`. Read paths present on |
| 45 | +the backend use that backend; missing read paths use the original builtin. |
| 46 | +Modes containing `w`, `a`, or `x` always use the backend. |
| 47 | + |
| 48 | +Backend calls receive `mode`, `encoding`, `errors`, and `newline`. `buffering`, |
| 49 | +`closefd`, and `opener` are forwarded only on the local fallback path. Nested |
| 50 | +installations do not form a restoration stack. |
| 51 | + |
| 52 | +### `uninstall_open_hook()` |
| 53 | + |
| 54 | +Restores the builtin saved when `fsspec_python.open` was imported. |
| 55 | + |
| 56 | +## Other modules |
| 57 | + |
| 58 | +`fsspec_python.utils.normalize_fsspec(fs=None, target_protocol=None, target_options=None, fo="", **kwargs)` returns a protocol/root string. Exactly |
| 59 | +one of `fs` and `target_protocol` is required. The key does not include credentials |
| 60 | +or storage options. |
| 61 | + |
| 62 | +The `path` and `pathlib` modules contain no implemented hooks. |
0 commit comments