gigl.common#

Common utilities, services, and tools used throughout GiGL.

Submodules#

Classes#

GcsUri

Represents a Google Cloud Storage (GCS) URI.

HttpUri

Represents an HTTP URI.

LocalUri

Represents a local URI (Uniform Resource Identifier) that extends the Uri class and implements the os.PathLike interface.

Uri

A URI; currently supports GCS ('gs://foo/bar'), HTTP ('http://abc.com/xyz') or local ('/foo/bar').

UriFactory

Factory class to create the proper concrete Uri instance given an input.

Package Contents#

class gigl.common.GcsUri(uri)[source]#

Bases: gigl.common.types.uri.uri.Uri

Represents a Google Cloud Storage (GCS) URI.

Parameters:

uri (Union[str, Path, GcsUri]) – The URI string or path to initialize the GcsUri object.

classmethod is_valid(uri, raise_exception=False)[source]#

Check if the given URI is valid.

Parameters:
  • uri (Union[str, Path, Uri]) – The URI to be validated.

  • raise_exception (Optiona[bool]) – Whether to raise an exception if the URI is invalid. Defaults to False.

Returns:

True if the URI is valid, False otherwise.

Return type:

bool

classmethod join(token, *tokens)[source]#

Joins multiple URI tokens together and returns a new GcsUri object.

Parameters:
  • token (Union[str, Path, Uri]) – The first URI token to join.

  • *tokens (Union[str, Path, Uri]) – Additional URI tokens to join.

Returns:

A new GcsUri object representing the joined URI.

Return type:

GcsUri

property bucket: str#
Return type:

str

property path: str#
Return type:

str

class gigl.common.HttpUri(uri)[source]#

Bases: gigl.common.types.uri.uri.Uri

Represents an HTTP URI.

Parameters:

uri (Union[str, pathlib.Path, HttpUri])

classmethod is_valid(uri, raise_exception=False)[source]#

Check if the URI is valid.

Parameters:
  • uri (Union[str, pathlib.Path, gigl.common.types.uri.uri.Uri]) – The URI to check.

  • raise_exception (bool) – Whether to raise an exception if the URI is invalid.

Returns:

True if the URI is valid, False otherwise.

Return type:

bool

classmethod join(token, *tokens)[source]#

Join multiple URI tokens into a single URI.

Parameters:
Returns:

The joined URI.

Return type:

HttpUri

class gigl.common.LocalUri(uri)[source]#

Bases: gigl.common.types.uri.uri.Uri, os.PathLike

Represents a local URI (Uniform Resource Identifier) that extends the Uri class and implements the os.PathLike interface.

Parameters:

uri (Union[str, pathlib.Path, Uri])

absolute()[source]#

Returns an absolute LocalUri object.

Returns:

An absolute LocalUri object.

Return type:

LocalUri

classmethod is_valid(uri, raise_exception=False)[source]#

Checks if the given URI is valid.

Parameters:
  • uri (Union[str, Path, Uri]) – The URI to check.

  • raise_exception (Optional[bool]) – Whether to raise an exception if the URI is invalid. Defaults to False.

Returns:

True if the URI is valid, False otherwise.

Return type:

bool

classmethod join(token, *tokens)[source]#

Joins multiple URI tokens together and returns a new LocalUri object.

Parameters:
  • token (Union[str, Path, Uri]) – The first URI token to join.

  • *tokens (Union[str, Path, Uri]) – Additional URI tokens to join.

Returns:

A new LocalUri object representing the joined URI.

Return type:

LocalUri

class gigl.common.Uri(uri)[source]#

Bases: object

A URI; currently supports GCS (‘gs://foo/bar’), HTTP (‘http://abc.com/xyz’) or local (‘/foo/bar’).

Parameters:

uri (Union[str, pathlib.Path, Uri])

get_basename()[source]#

The base name is the final component of the path, effectively extracting the file or directory name from a full path string. i.e. get_basename(“/foo/bar.txt”) -> bar.txt get_basename(“gs://bucket/foo”) -> foo

Return type:

str

classmethod is_valid(uri, raise_exception=False)[source]#
Abstractmethod:

Parameters:
  • uri (Union[str, pathlib.Path, Uri])

  • raise_exception (bool)

Return type:

bool

Check if the given URI is valid.

Parameters:
  • uri (Union[str, pathlib.Path, Uri]) – The URI to check.

  • raise_exception (bool) – Whether to raise an exception if the URI is invalid.

Returns:

True if the URI is valid, False otherwise.

Return type:

bool

classmethod join(token, *tokens)[source]#

Join multiple tokens to create a new Uri instance.

Parameters:
  • token (Union[str, pathlib.Path, Uri]) – The first token to join.

  • tokens (Union[str, pathlib.Path, Uri]) – Additional tokens to join.

Returns:

A new Uri instance representing the joined URI.

Return type:

Uri

property uri#
class gigl.common.UriFactory[source]#

Factory class to create the proper concrete Uri instance given an input.

static create_uri(uri)[source]#

Create a Uri object based on the given URI string, path, or existing Uri object.

Parameters:

uri (Union[str, Path, Uri]) – The URI string, path, or existing Uri object.

Returns:

A created Uri object based on the given input.

Return type:

Uri