VsiFileSystem#

class VsiFileSystem[source]#

Bases: FileSystem

A FileSystem to access files over any protocol supported by GDAL’s VSI

__init__()#

Methods

__init__()

copy_from(src_uri, dst_path)

Copy a source file to a local destination.

copy_to(src_path, dst_uri)

Copy a local source file to a destination.

file_exists(vsipath[, include_dir])

Check if a file exists.

get_file_system(uri[, mode])

Return FileSystem that should be used for the given URI/mode pair.

last_modified(vsipath)

Get the last modified date of a file.

list_children(vsipath[, ext])

List filenames of children rooted at URI.

list_paths(vsipath[, ext])

List paths rooted at URI.

local_path(vsipath, download_dir)

Return the path where a local copy should be stored.

matches_uri(uri, mode)

Returns True if this FS can be used for the given URI/mode pair.

parse_archive_format(uri)

read_bytes(vsipath)

Read contents of URI to bytes.

read_str(uri)

Read contents of URI to a string.

sync_from_dir(src_dir_uri, dst_dir[, delete])

Syncs a source directory to a local destination directory.

sync_to_dir(src_dir, dst_dir_uri[, delete])

Syncs a local source directory to a destination directory.

uri_to_vsi_path(uri)

A function to convert Rasterio-like URIs to VSI path strings

write_bytes(vsipath, data)

Write bytes in data to URI.

write_str(uri, data)

Write string in data to URI.

static copy_from(src_uri: str, dst_path: str)[source]#

Copy a source file to a local destination.

If the FileSystem is remote, this involves downloading.

Parameters
  • src_uri (str) – uri of source that can be copied from by this FileSystem

  • dst_path (str) – local path to destination file

static copy_to(src_path: str, dst_uri: str)[source]#

Copy a local source file to a destination.

If the FileSystem is remote, this involves uploading.

Parameters
  • src_path (str) – local path to source file

  • dst_uri (str) – uri of destination that can be copied to by this FileSystem

static file_exists(vsipath: str, include_dir: bool = True) bool[source]#

Check if a file exists.

Parameters
  • uri – The URI to check

  • include_dir (bool) – Include directories in check, if this file_system supports directory reads. Otherwise only return true if a single file exists at the URI.

  • vsipath (str) –

Return type

bool

static get_file_system(uri: str, mode: str = 'r') FileSystem#

Return FileSystem that should be used for the given URI/mode pair.

Parameters
  • uri (str) – URI of file

  • mode (str) – mode to open file in, ‘r’ or ‘w’

Return type

FileSystem

static last_modified(vsipath: str) datetime.datetime | None[source]#

Get the last modified date of a file.

Parameters
  • uri – the URI of the file

  • vsipath (str) –

Returns

the last modified date in UTC of a file or None if this FileSystem does not support this operation.

Return type

datetime.datetime | None

static list_children(vsipath: str, ext: str | None = None) list[str][source]#

List filenames of children rooted at URI.

Optionally only includes filenames with a certain file extension.

Parameters
  • uri – The URI of a directory.

  • ext (str | None) – The optional file extension to filter by.

  • vsipath (str) –

Returns

List of filenames excluding “.” or “..”.

Return type

list[str]

static list_paths(vsipath: str, ext: str | None = None) list[str][source]#

List paths rooted at URI.

Optionally only includes paths with a certain file extension.

Parameters
  • uri – the URI of a directory

  • ext (str | None) – the optional file extension to filter by

  • vsipath (str) –

Return type

list[str]

static local_path(vsipath: str, download_dir: str) str[source]#

Return the path where a local copy should be stored.

Parameters
  • uri – the URI of the file to be copied

  • download_dir (str) – path of the local directory in which files should be copied

  • vsipath (str) –

Return type

str

static matches_uri(uri: str, mode: str) bool[source]#

Returns True if this FS can be used for the given URI/mode pair.

Parameters
  • uri (str) – URI of file

  • mode (str) – mode to open file in, ‘r’ or ‘w’

Return type

bool

static parse_archive_format(uri: str) Match[source]#
Parameters

uri (str) –

Return type

Match

static read_bytes(vsipath: str) bytes[source]#

Read contents of URI to bytes.

Parameters

vsipath (str) –

Return type

bytes

static read_str(uri: str) str[source]#

Read contents of URI to a string.

Parameters

uri (str) –

Return type

str

static sync_from_dir(src_dir_uri: str, dst_dir: str, delete: bool = False)[source]#

Syncs a source directory to a local destination directory.

If the FileSystem is remote, this involves downloading.

Parameters
  • src_dir_uri (str) – source directory that can be synced from by this FileSystem

  • dst_dir (str) – A local destination directory

  • delete (bool) – True if the destination should be deleted first.

static sync_to_dir(src_dir: str, dst_dir_uri: str, delete: bool = False)[source]#

Syncs a local source directory to a destination directory.

If the FileSystem is remote, this involves uploading.

Parameters
  • src_dir (str) – local source directory to sync from

  • dst_dir_uri (str) – A destination directory that can be synced to by this FileSystem

  • delete (bool) – True if the destination should be deleted first.

static uri_to_vsi_path(uri: str) str[source]#

A function to convert Rasterio-like URIs to VSI path strings

Parameters

uri (str) – URI of the file, possibly nested within archives as follows <archive_scheme>+<archive_URI>!path/to/contained/file.ext. Acceptable URI schemes are file, s3, gs, http, https, and ftp. Allowable archive schema are tar, zip, and gzip.

Raises

ValueError – If URI format or schema is invalid.

Return type

str

static write_bytes(vsipath: str, data: bytes)[source]#

Write bytes in data to URI.

Parameters
static write_str(uri: str, data: str)[source]#

Write string in data to URI.

Parameters
  • uri (str) –

  • data (str) –