shapelib.core.cloud package#

Cloud storage infrastructure for remote file operations.

Subpackages#

Submodules#

shapelib.core.cloud.cloud_path module#

Value Object for parsing and representing cloud/local file paths.

class shapelib.core.cloud.cloud_path.CloudPath(raw_path, scheme, host, path, extension, query, _REMOTE_SCHEMES=frozenset({'az', 'gs', 'http', 'https', 's3'}))[source]#

Bases: object

Immutable Value Object representing a file path (local or remote).

This class parses URLs and local paths to extract scheme, host, path, and file extension. It handles query strings in URLs (e.g., AWS presigned URLs) correctly by extracting the extension from the path component only.

Parameters:
Variables:
  • raw_path (str) – The original path or URL as provided.

  • scheme (str) – The URL scheme (e.g., ‘https’, ‘s3’, ‘gs’, ‘file’, or empty for local).

  • host (str) – The host/bucket name for remote URLs, empty for local paths.

  • path (str) – The path component (without query string).

  • extension (str) – The file extension (e.g., ‘.fgb’, ‘.shp’).

  • query (str) – The query string component (for presigned URLs).

Examples

Parse a presigned S3 URL:

>>> cloud_path = CloudPath.from_string(
...     "https://bucket.s3.amazonaws.com/file.fgb?X-Amz-Signature=..."
... )
>>> cloud_path.extension
'.fgb'
>>> cloud_path.is_remote
True

Parse a local path:

>>> local_path = CloudPath.from_string("/home/user/data.shp")
>>> local_path.is_remote
False

Big-O

O(n) where n is the length of the path string.

raw_path: str#
scheme: str#
host: str#
path: str#
extension: str#
query: str#
classmethod from_string(path)[source]#

Create a CloudPath from a string or Path object.

Parameters:

path (str | Path) – The path or URL to parse.

Returns:

A new CloudPath instance with parsed components.

Return type:

CloudPath

Raises:

ValueError – If the path is empty or None.

property is_remote: bool#

Check if this path represents a remote location.

property is_s3_protocol: bool#

//).

Type:

Check if this path uses the S3 protocol (s3

property is_https: bool#

Check if this path uses HTTP/HTTPS protocol.

property full_url: str#

Reconstruct the full URL including query string.

property s3_bucket: str | None#

Extract S3 bucket name from path.

property s3_key: str | None#

Extract S3 object key from path.

property vsicurl_path: str#

Build the GDAL virtual filesystem path for streaming.

Returns:

The /vsicurl/ or /vsis3/ path for GDAL.

Return type:

str