Package: gcp-pilot
Google Cloud PilotInstallationpip install gcp-pilotSome APIs need extra packages, thus you must useextrasto add them:Cloud Tasks:pip install gcp-pilot[tasks]Cloud Build:pip install gcp-pilot[build]Cloud Storage:pip install gcp-pilot[storage]Big Query:pip install gcp-pilot[bigquery]Speech:pip install gcp-pilot[speech]Sheets:pip install gcp-pilot[sheets]Pub/Sub:pip install gcp-pilot[pubsub]Datastore:pip install gcp-pilot[datastore]Cloud DNS:pip install gcp-pilot[dns]Secret Manager:pip install gcp-pilot[secret]Healthcare Engine:pip install gcp-pilot[healthcare]IAM:pip install gcp-pilot[iam]Usagefrom gcp_pilot.resource import ResourceManager

grm = ResourceManager()Default ValuesCredentialsgcp-pilotusesADCto detect credentials. This means that you must have one of the following setups:Environment variableGOOGLE_APPLICATION_CREDENTIALSpointing to the JSON file with the credentialsRun inside GCP (Compute Engine, Cloud Run, GKE, AppEngine), so the machine's credentials will be usedRun locally after authenticating withgcloud auth application-default loginYou can also globally set a service account using the environment variableDEFAULT_SERVICE_ACCOUNT, which will require impersonation.ProjectWhen creating a client, a default project is defined by using the project that the credentials belongs to.Clients that support managing resources from other projects can be overwritten per call.Example: you create aBigQueryclient using credentials fromproject_a.
All calls will query datasets fromproject_a, unless another project is passed as parameter when performing the call.You can also globally set a project using the environment variableDEFAULT_PROJECTLocationVery similar to default project, a default location is defined by using the project's location.
The project's location will exist if you ever enabled AppEngine, so you had to set a location then.
Otherwise, no default location will be set.You can also globally set a location using the environment variableDEFAULT_LOCATIONand reduce the amount of API calls
when creating clients.Why Usegcp-pilot"Since Google already has ageneric API clientand so manyspecific clients, why should I use this library?"Google's has 2 types of clients:dedicated: custom-made for the APIs. They are excellent: they implement high level interaction with the API with friendly methods. Thegcp-pilotcan adds its value by handling authentication, friendly errors and parameter fallback.generic: a single client that is capable of dynamically calling any REST API. They are a pain to use: very specific calls that must be translated from the documentation. Thegcp-pilotcomes in handy to add high-level interaction with friendly method such asCalendar.create_event, on top of all other vantages cited above.Parameter FallbackMost API endpoints requireproject_id(sometimes evenproject_number) andlocation.Sogcp-pilotautomatically detects these values for you, based on your credentials (although it'll require extra permissions and API calls).If you use multiple projects, and your credentials is accessing other projects, you can still customize the parameters on each call to avoid the default fallback.Friendly ErrorsMost APIs return a genericHttpExceptionwith am embedded payload with error output, and also there's a couple of different structures for these payloads.Sogcp-pilottries its best to convert these exceptions into more friendly ones, such asNotFound,AlreadyExistsandNotAllowed.It'll be much easier to capture these exceptions and handle them by its type.Identification FeaturesAuthentication: each client usesADC,
which consists on trying to detect the service account with fallbacks: SDK > Environment Variable > MetadataImpersonation: it's possible to create clients withimpersonate_accountparameter thatimpersonatesanother account.Delegation: services(eg. Google Workspace)that requires specific subjects are automatically delegated, sometimes even performing additional credential signatures.Region: most GCP services requires a location to work on(some even require specific locations). If not provided, the clients use the project's default location, as defined by App Engine.Authorization: OIDC authorization is automatically generated for services(eg. CloudRun)that require authentication to be used.Auto-AuthorizationSome services require specific authorizations that should be setup prior to its usage, some examples:[Pub/Sub] subscribe to a topic with authenticated push;[Cloud Scheduler] schedule a job to trigger a Cloud Run service;[Cloud Tasks] queue a task to trigger a Cloud Run service;In these cases,gcp-pilottries its best to assure that the required permissions are properly set up
before the actual request is made.IntegrationSome services can be integrated, andgcp-pilotdoes just that in a seamless way by adding helper methods.Example: you can subscribe to Google Cloud Build's events to be notified by every build step.By usingCloudBuild.subscribe, thegcp-pilotcreates a subscription (and the topic, if needed) in the Google Pub/Sub service.Supported APIsIAMmanage service accountsmanage permissionsencode & decode JWT tokensIdentity Platformsign in userssign up usersreset password flowverify email flowgenerate authentication magic links (OOB tokens)manage authorized domainsCredentialsmanage API KeysResource Managermanage projectsmanage permissionsSecret Managermanage secretsIdentity Aware Proxygenerate OIDC tokenSource Repositoriesmanage repositoriesDirectory:manage usersmanage groupsPeople:get peopleCloud SQLmanage instancesmanage databasesmanage usersCloud Storagemanage bucketsmanage filesCloud Buildmanage triggersCloud Functionsmanager functionsmanage permissionsCloud Schedulermanage schedulesCloud Tasksmanage tasks & queuesCloud Runread servicesmanage domain mappings[1]API Gatewaymanage APIsmanage API Configsmanage GatewaysService Usageenable/disable APIs and ServicesBigQuerymanage datasetsperform queriesCalendarmanage eventsGoogle Chatsbuild complex messagescall webhookinteract as botCloud Directorymanage groupsCloud DNSmanage DNS zonesmanage zone's registersSheetsmanage spreadsheets (powered by gspread)Speechrecognize speech from audioDatastoreObject Mapping ("ORM-ish" management of documents)Monitoringreporting errorsloggingmanage custom servicesHealthcareManage datasetsManage storesManage FHIR resources:powered byfhir-resourcesDatastreamRead/Delete streamsRead Stream's ObjectsStart/Stop object backfill