Registry / gcp / google-cloud-securitycenter

google-cloud-securitycenter

JSON →
library1.45.0pypypi✓ verified 87d ago

Google Cloud Security Command Center (SCC) is a security and data risk platform that helps you prevent, detect, and respond to threats across your Google Cloud assets. It identifies security misconfigurations, surfaces suspicious activity, and provides actionable recommendations. The `google-cloud-securitycenter` client library for Python, currently at version 1.44.0, provides programmatic access to the SCC API and is frequently updated to support new features and API versions.

pip install google-cloud-securitycenter
INSTALL
IMPORT
SIG · GOOGLE-CLOUD-SECUR
G
google-cloud-securitycenter
gcppythonv1.45.0
Install
5.7s avg
Import
2158ms
Disk
77MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.45.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 2.617s · 77.9MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 5.7s · import 1.699s · 76MB
77MB installed
● package 77MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SecurityCenterClient
✓ from google.cloud.securitycenter import SecurityCenterClient
✗ from google.cloud import securitycenter_v1

This quickstart initializes the Security Command Center client and lists all available security sources within a specified Google Cloud organization. Ensure your environment is authenticated (e.g., via `GOOGLE_APPLICATION_CREDENTIALS` or `gcloud auth application-default login`) and the `GOOGLE_CLOUD_ORGANIZATION_ID` environment variable is set.

import os from google.cloud import securitycenter_v1 from google.api_core.exceptions import GoogleAPIError # Ensure GOOGLE_APPLICATION_CREDENTIALS points to a service account key file # or use `gcloud auth application-default login`. # Set your Google Cloud Organization ID as an environment variable or replace the placeholder. organization_id = os.environ.get('GOOGLE_CLOUD_ORGANIZATION_ID', 'YOUR_ORGANIZATION_ID') def list_scc_sources(org_id: str): """Lists all Security Command Center sources for an organization.""" if org_id == 'YOUR_ORGANIZATION_ID': print("Please set the GOOGLE_CLOUD_ORGANIZATION_ID environment variable or replace 'YOUR_ORGANIZATION_ID'.") return client = securitycenter_v1.SecurityCenterClient() parent = f"organizations/{org_id}" print(f"Listing SCC sources for organization: {parent}") try: # Paging through all results for source in client.list_sources(parent=parent): print(f" Source: {source.display_name} (Name: {source.name})") except GoogleAPIError as e: print(f"An API error occurred: {e}") except Exception as e: print(f"An unexpected error occurred: {e}") if __name__ == "__main__": list_scc_sources(organization_id)
Debug
Known issues
gotchaAuthentication is critical for Google Cloud client libraries. Incorrect setup of Application Default Credentials (ADC) or service account keys will lead to API errors.
fix
Ensure `GOOGLE_APPLICATION_CREDENTIALS` environment variable points to a valid service account JSON key file, or run `gcloud auth application-default login` for local development. Verify the service account has the necessary IAM roles for Security Command Center (e.g., `securitycenter.viewer`).
affects: All versions
breakingUsing older or beta API versions (e.g., `v1p1beta1`) might introduce breaking changes. While `google-cloud-securitycenter` typically uses `v1`, ensure you are aware if interacting with a specific version.
fix
Prefer the stable API version (e.g., `securitycenter_v1`) for production. Consult the official API reference for any version-specific considerations or migrations if using non-GA versions.
affects: All versions, especially when switching API versions manually.
gotchaThe `SecurityCenterClient` uses a context manager (`with client:`) to ensure proper resource cleanup. If the client's underlying transport is shared with other clients, using `with` can prematurely close connections for other clients.
fix
If sharing a transport, instantiate the client normally (`client = securitycenter_v1.SecurityCenterClient()`) and manage its lifecycle manually, ensuring `client.close()` is called when no longer needed. Otherwise, use `with securitycenter_v1.SecurityCenterClient() as client:` for isolated usage.
affects: All versions
Upgrade
Version history
1.45.0latest on PyPI · released Jun 3, 2026
Audit
Dependencies
PythonrequiredRequired Python runtime version.
Agent activity
35 hits · last 30 days
node
32
OpenAI (training)
1
Resources
google-cloud-securitycenter — pip install google-cloud-securitycenter · libregistry