Pyjo.GCP.Credentials - Credentials of Google Cloud

from Pyjo.GCP.Credentials import Credentials

credentials = Credentials(token='ya29.a0AfH6SM...')

# Or import the module, as in Google Python Style Guide

import Pyjo.GCP.Credentials.Chain

# The Application Default Credentials, blocking
credentials = Pyjo.GCP.Credentials.Chain.new().credentials()
print(credentials.project, credentials.expiration, credentials.provider)

# Non-blocking
Pyjo.GCP.Credentials.Chain.new().credentials_p().then(lambda credentials: print(credentials.provider)).wait()

Pyjo.GCP.Credentials is the credentials of Google Cloud that authorize a request: an access token of OAuth 2.0, which a request has as Authorization: Bearer, with its expiration, and what the credentials know of the project, the quota project and the universe domain. A provider of Pyjo.GCP.Credentials.Provider gets them, as Pyjo.GCP.Credentials.Chain gets the Application Default Credentials.

The providers are those of the credentials of google-auth, of a file of credentials of its type, which Pyjo.GCP.Credentials.File makes the provider of, and of the metadata server:

Credentials

type of the file

Provider

a user of gcloud auth application-default login

authorized_user

Pyjo.GCP.Credentials.AuthorizedUser

the key of a service account, with a self-signed JWT or the domain-wide delegation

service_account

Pyjo.GCP.Credentials.ServiceAccount

an impersonated service account, of the credentials of its source

impersonated_service_account

Pyjo.GCP.Credentials.Impersonated

Workload Identity Federation of a token of a file or a URL, or of a certificate of X.509

external_account

Pyjo.GCP.Credentials.IdentityPool

Workload Identity Federation of a token of an executable

external_account with executable

Pyjo.GCP.Credentials.Pluggable

Workload Identity Federation of AWS

external_account of AWS

Pyjo.GCP.Credentials.AWS

a user of a workforce pool, of gcloud auth application-default login --login-config

external_account_authorized_user

Pyjo.GCP.Credentials.ExternalAccountAuthorizedUser

the service account of Compute Engine, GKE, Cloud Run and Cloud Functions

none, the metadata server

Pyjo.GCP.Credentials.Metadata

See also

Pyjo.GCP.Credentials.Provider, Pyjo.GCP.Credentials.Chain, Pyjo.GCP.

Classes

Pyjo.GCP.Credentials.CLOUD_PLATFORM = 'https://www.googleapis.com/auth/cloud-platform'

The scope of all the APIs of Google Cloud, of the tokens of the providers that take scopes by default.

class Pyjo.GCP.Credentials.Pyjo_GCP_Credentials(*, token: str, expiration: datetime | None = None, project: str | None = None, quota_project: str | None = None, universe_domain: str | None = None, account: str | None = None, provider: str | None = None)[source]

Pyjo.GCP.Credentials inherits all attributes and methods from Pyjo.Base and implements the following new ones.

__init__(*, token: str, expiration: datetime | None = None, project: str | None = None, quota_project: str | None = None, universe_domain: str | None = None, account: str | None = None, provider: str | None = None) → None[source]
credentials = Pyjo.GCP.Credentials.new(token='ya29.a0AfH6SM...')

Construct a new Pyjo.GCP.Credentials object.

__repr__() → str[source]

Return repr(self).

__weakref__

list of weak references to the object

account
account = credentials.account

The account of the credentials, as the email of a user or of a service account, where the provider knows it, or None.

copy(**changes: Any) → Pyjo_GCP_Credentials[source]
credentials = credentials.copy(project='myproject')

A new Pyjo.GCP.Credentials object of the same attributes, with the changes of the arguments.

expiration
expiration = credentials.expiration

The time when the token expires, with its time zone, or None for a token whose expiration is not known.

expires_in(now: datetime | None = None) → float | None[source]
seconds = credentials.expires_in()

The number of seconds until the token expires, negative once it has, or None for a token whose expiration is not known.

project
project = credentials.project

The project of the credentials, as the one of the key of a service account, or of the environment of Pyjo.GCP.Credentials.Chain, or None.

provider
name = credentials.provider

The name of the provider of the credentials, as authorized_user, or None.

quota_project
project = credentials.quota_project

The project that the quota and the billing of the requests go to, of the header x-goog-user-project, or None.

token
token = credentials.token

The access token.

universe_domain
domain = credentials.universe_domain

The universe domain of the credentials, or None for the one of Pyjo.GCP.Config.

Pyjo.GCP.Credentials.expiration_in(seconds: Any) → datetime[source]
expiration = Pyjo.GCP.Credentials.expiration_in(3599)

The time of the expiration of a token of expires_in of OAuth 2.0, a number of seconds from now, or a string of it, as some endpoints give it.

Pyjo.GCP.Credentials.parse_time(value: str) → datetime[source]
expiration = Pyjo.GCP.Credentials.parse_time('2026-11-04T12:00:00Z')

A time of RFC 3339, as the expiration of a token of IAM Credentials, with its time zone, UTC when it has none.