Skip to content

gc_batch.google_utils

Google Cloud utility functions for gc-batch.

This module provides utility functions for working with Google Cloud resources, including parsing job resource names.

Classes:

Name Description
GoogleUtils

Static utility methods for Google Cloud operations.

GoogleUtils

Utility methods for working with Google Cloud Batch jobs.

Provides static methods for parsing job resource names.

Example
from gc_batch.google_utils import GoogleUtils

job = client.get_job("my-job")

# Get just the job name (without the full resource path)
job_name = GoogleUtils.get_job_name(job)
# Returns: "my-job-1234567890"

# Get the project ID from the job
project_id = GoogleUtils.get_project_id(job)
# Returns: "my-project-id"
Source code in src/gc_batch/google_utils.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class GoogleUtils:
    """Utility methods for working with Google Cloud Batch jobs.

    Provides static methods for parsing job resource names.

    Example:
        ```python
        from gc_batch.google_utils import GoogleUtils

        job = client.get_job("my-job")

        # Get just the job name (without the full resource path)
        job_name = GoogleUtils.get_job_name(job)
        # Returns: "my-job-1234567890"

        # Get the project ID from the job
        project_id = GoogleUtils.get_project_id(job)
        # Returns: "my-project-id"
        ```
    """

    @staticmethod
    def get_project_id(job: GCSBatchJob) -> str:
        """Extract the project ID from a job's resource name.

        Args:
            job: The GCSBatchJob object.

        Returns:
            The project ID extracted from the job's full resource path.

        Example:
            For a job with name "projects/my-project/locations/us-central1/jobs/job01",
            returns "my-project".
        """
        # this will be like: projects/123456/locations/us-central1/jobs/job01
        # so we want to return the 123456
        return job.name.split("/")[1]

    @staticmethod
    def get_job_name(job: GCSBatchJob) -> str:
        """Extract the job name from a job's resource name.

        Args:
            job: The GCSBatchJob object.

        Returns:
            The job name (last segment of the resource path).

        Example:
            For a job with name "projects/my-project/locations/us-central1/jobs/my-job",
            returns "my-job".
        """
        return job.name.split("/")[-1]

get_job_name(job) staticmethod

Extract the job name from a job's resource name.

Parameters:

Name Type Description Default
job Job

The GCSBatchJob object.

required

Returns:

Type Description
str

The job name (last segment of the resource path).

Example

For a job with name "projects/my-project/locations/us-central1/jobs/my-job", returns "my-job".

Source code in src/gc_batch/google_utils.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
@staticmethod
def get_job_name(job: GCSBatchJob) -> str:
    """Extract the job name from a job's resource name.

    Args:
        job: The GCSBatchJob object.

    Returns:
        The job name (last segment of the resource path).

    Example:
        For a job with name "projects/my-project/locations/us-central1/jobs/my-job",
        returns "my-job".
    """
    return job.name.split("/")[-1]

get_project_id(job) staticmethod

Extract the project ID from a job's resource name.

Parameters:

Name Type Description Default
job Job

The GCSBatchJob object.

required

Returns:

Type Description
str

The project ID extracted from the job's full resource path.

Example

For a job with name "projects/my-project/locations/us-central1/jobs/job01", returns "my-project".

Source code in src/gc_batch/google_utils.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
@staticmethod
def get_project_id(job: GCSBatchJob) -> str:
    """Extract the project ID from a job's resource name.

    Args:
        job: The GCSBatchJob object.

    Returns:
        The project ID extracted from the job's full resource path.

    Example:
        For a job with name "projects/my-project/locations/us-central1/jobs/job01",
        returns "my-project".
    """
    # this will be like: projects/123456/locations/us-central1/jobs/job01
    # so we want to return the 123456
    return job.name.split("/")[1]