vs_common package
Submodules
vs_common.archive module
archive.py
This module contains functions for handling archives.
- class vs_common.archive.Archive(path: str | AbstractBufferedFile)[source]
Bases:
ABC
- abstract extract_file(f: TarInfo | ZipInfo) ExFileObject | ZipExtFile [source]
Extract a file in memory
- Parameters:
f (InfoFile) – Valid info file
- Returns:
Extracted file
- Return type:
ExFile
- class vs_common.archive.GzArchive(path: str | AbstractBufferedFile)[source]
Bases:
Archive
Handles .gz archives
- class vs_common.archive.TarArchive(path: str | AbstractBufferedFile)[source]
Bases:
Archive
Handles .tar and .tar.gz archives
- extract_file(f)[source]
Extract a file in memory
- Parameters:
f (InfoFile) – Valid info file
- Returns:
Extracted file
- Return type:
ExFile
- class vs_common.archive.ZipArchive(path: str | AbstractBufferedFile)[source]
Bases:
Archive
Handles .zip archives
- extract_file(f)[source]
Extract a file in memory
- Parameters:
f (InfoFile) – Valid info file
- Returns:
Extracted file
- Return type:
ExFile
- vs_common.archive.archive_extract(path: str, regex: str, to_path: str) str [source]
Extracts the first file matching regex from archive
vs_common.config module
- vs_common.config.load_config(cfg_path: str, configuration_class: Type[ServiceConfig], overrides: Tuple[str] | None = None) ServiceConfig [source]
Load the configuration as structured config
- Parameters:
cfg_path (str) – File path to configuration
configuration_class (Type[ServiceConfig]) – Main, top level model of configuration, a dataclass reference
overrides –
Optional[Tuple[str]]: Tuple of dotlist overrides. Example: (“config.value=42”, “foo.bar=baz”) overrides a yaml config and creates the following yaml
config: value: 42 foo: bar: baz
- Returns:
Structured configuration
- Return type:
ServiceConfig
vs_common.filesystem module
filesystem.py
This module contains functions for handling filesystems via model.
- vs_common.filesystem.authentication_environment(filesystem_config: FilesystemConfig) Iterator [source]
Set appropriate authentication environment variables from the given config
- Parameters:
auth_config (FilesystemConfig) – Storage authentication configuration
- vs_common.filesystem.get_filesystem(filesystem_config: FilesystemConfig) AbstractFileSystem [source]
Initialize appropriate filesystem from given config
- Parameters:
filesystem_config (FilesystemConfig) – Filesystem configuration
- Returns:
fsspec filesystem
- Return type:
fsspec.AbstractFileSystem
vs_common.model module
model.py
This module contains the view server shared configuration models
- class vs_common.model.CatalogConfig(id: str = 'vs-stac-catalog', description: str = 'View Server STAC catalog', title: str = 'VS Catalog')[source]
Bases:
object
- class vs_common.model.FilesystemConfig(type: vs_common.model.FilesystemType, s3: vs_common.model.S3FilesystemConfig | None = None, swift: vs_common.model.SwiftFileystemConfig | None = None, local: vs_common.model.LocalFilesystemConfig | None = None, sshfs: vs_common.model.SSHFilesystemConfig | None = None)[source]
Bases:
object
- local: LocalFilesystemConfig | None = None
- s3: S3FilesystemConfig | None = None
- sshfs: SSHFilesystemConfig | None = None
- swift: SwiftFileystemConfig | None = None
- type: FilesystemType
- class vs_common.model.FilesystemType(value)[source]
-
An enumeration.
- file = 'file'
- s3 = 's3'
- sshfs = 'sshfs'
- swift = 'swift'
- class vs_common.model.S3FilesystemConfig(access_key_id: str = '', secret_access_key: str = '', endpoint_url: str = '', region: str = '', public: bool = False)[source]
Bases:
object
vs_common.stac module
stac.py
This module contains functions for STAC concepts.
- class vs_common.stac.FSSpecStacIO(headers: Dict[str, str] | None = None)[source]
Bases:
StacIO
Extension of StacIO to allow working with different filesystems using fsspec.
- read_text(source: str | PathLike, *args: Any, **kwargs: Any) str [source]
Read text from the given URI.
The source to read from can be specified as a string or
os.PathLike
object (Link
is a path-like object). If it is a string, it must be a URI or local path from which to read. Using aLink
enables implementations to use additional link information, such as paging information contained in the extended links described in the STAC API spec.- Parameters:
source – The source to read from.
*args – Arbitrary positional arguments that may be utilized by the concrete implementation.
**kwargs – Arbitrary keyword arguments that may be utilized by the concrete implementation.
- Returns:
The text contained in the file at the location specified by the uri.
- Return type:
- write_text(dest: str | PathLike, txt: str, *args: Any, **kwargs: Any) None [source]
Write the given text to a file at the given URI.
The destination to write to can be specified as a string or
os.PathLike
object (Link
is a path-like object). If it is a string, it must be a URI or local path from which to read. Using aLink
enables implementations to use additional link information.- Parameters:
dest – The destination to write to.
txt – The text to write.
- vs_common.stac.create_item(old_item: Item, metadata: Dict, assets: Dict[str, Asset], overwrite_metadata: bool = True) Item [source]
Create a new item from an existing item
- Parameters:
old_item (Item) – Existing old item
metadata (Dict) – Metadata to add to properties
assets (Dict[str, Asset]) – Assets to plug in
overwrite_metadata – (bool): Attempt to overwrite metadata. If set to False,
True. (sets these as None. Defaults to)
- Returns:
A new item ready for upload
- Return type:
Item
- vs_common.stac.encode_item(output: Item) str [source]
Encodes item as json
- Parameters:
output (Item) – Item to encode
- Returns:
JSON encoded item
- Return type:
- vs_common.stac.get_item(json_item_or_path: str) Item | None [source]
Get item from json string or from file
- Parameters:
item (str) – JSON encoded stac item or path to a file
- Returns:
pystac.Item resolved item
- Return type:
Item
- vs_common.stac.get_or_create_catalog(catalog_path: str, catalog_config: CatalogConfig = CatalogConfig(id='vs-stac-catalog', description='View Server STAC catalog', title='VS Catalog')) Catalog [source]
Retrieves or creates a new stac catalog from given filesystem config parameters
- Parameters:
catalog_path (str) – Path to STAC catalog. By default sits at the root of each filesystem with file named catalog.json. Example: s3://bucket/catalog.json
filesystem_config (FilesystemConfig) – Filesystem configuration
catalog_config (CatalogConfig, optional) – Configuration of the catalog. Defaults to CatalogConfig().
- Returns:
STAC Catalog object
- Return type:
Catalog