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

abstract get_members() List[TarInfo | ZipInfo][source]

Return a list of archive info files

Returns:

List of InfoFiles

Return type:

List[InfoFile]

vsi_prefix: str = ''
exception vs_common.archive.ArchiveError[source]

Bases: Exception

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

get_members()[source]

Return a list of archive info files

Returns:

List of InfoFiles

Return type:

List[InfoFile]

vsi_prefix: str = '/vsitar/'
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

get_members()[source]

Return a list of archive info files

Returns:

List of InfoFiles

Return type:

List[InfoFile]

vsi_prefix: str = '/vsizip/'
vs_common.archive.archive_extract(path: str, regex: str, to_path: str) str[source]

Extracts the first file matching regex from archive

Parameters:
  • path (str) – Path to archive

  • regex (str) – Regex to extract

  • to_path (str) – Destination of extract

Returns:

Path to extracted file

Return type:

str

Searches the archive recursively for a file matching a regex

Parameters:
  • path (str) – Path to archive

  • regex (str) – Regular expression for searching

Raises:

ArchiveError – Raised when no matches are found

Returns:

All matched files in archive, formatted as vsi paths

Return type:

List[str]

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.config.validate_config(cfg_path: str, schema_path: str) None[source]

Validate config file against schema

Parameters:
  • cfg_path (str) – path to the yaml configuration file

  • schema_path (str) – path to the schema file, usually sitting at top of source directory

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.filesystem.upload(from_path: str, to_path: str) str[source]

Uploads file to given path

Parameters:
  • from_path (str) – File path to upload

  • to_path (str) – Destination path

Returns:

Final path of file

Return type:

str

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

description: str = 'View Server STAC catalog'
id: str = 'vs-stac-catalog'
title: str = 'VS Catalog'
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]

Bases: str, Enum

An enumeration.

file = 'file'
s3 = 's3'
sshfs = 'sshfs'
swift = 'swift'
class vs_common.model.LocalFilesystemConfig[source]

Bases: object

class vs_common.model.S3FilesystemConfig(access_key_id: str = '', secret_access_key: str = '', endpoint_url: str = '', region: str = '', public: bool = False)[source]

Bases: object

access_key_id: str = ''
endpoint_url: str = ''
public: bool = False
region: str = ''
secret_access_key: str = ''
class vs_common.model.SSHFilesystemConfig(host: str, username: str, password: str)[source]

Bases: object

host: str
password: str
username: str
class vs_common.model.SwiftFileystemConfig(user: str, key: str, region_name: str, authurl: str, auth_version: str, tenant_name: str)[source]

Bases: object

auth_version: str
authurl: str
key: str
region_name: str
tenant_name: str
user: str

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 a Link 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:

str

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 a Link 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:

str

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

vs_common.stac.get_or_create_collection(collection_id: str, catalog: Catalog) Collection[source]

Retrieves from catalog or creates a new STAC collection

Parameters:
  • collection_id (str) – Id of the collection

  • catalog (Catalog) – Catalog to crawl

Returns:

STAC Collection

Return type:

Collection

Module contents