Tiny helper to fetch Google Secret Manager secrets with optional service account keyfile support.
Project description
toolssecret
Tiny helper to fetch secrets from Google Secret Manager, with optional support for:
- ADC (Application Default Credentials) (default)
- A service account JSON keyfile (
service_account_file) - A service account info dict (
service_account_info) — useful for CI/CD where you inject JSON via env/secret manager
It’s designed so you can simply:
from toolssecret import get_secret
Install
From pypi
pip install toolssecret
Usage
1) Using ADC (Application Default Credentials)
from toolssecret import get_secret
value = get_secret(secret_name="api_key_test", project_id="myproject")
print(value)
2) Using a service account keyfile
from toolssecret import get_secret
value = get_secret(
secret_name="api_key_test",
project_id="myproject",
service_account_file="~/.config/gcloud/sa-keys/myserviceaccount.json",
)
print(value)
Notes:
service_account_filesupports~and environment variable expansion like$HOME/...(expanded by Python).
3) Using a service account info dict
This is useful when you keep the service account JSON in an environment variable or secret.
import json
import os
from toolssecret import get_secret
sa_info = json.loads(os.environ["GCP_SA_JSON"])
value = get_secret(
secret_name="api_key_test",
project_id="myproject",
service_account_info=sa_info,
)
print(value)
If you omit project_id, toolssecret will try to detect it in this order:
GOOGLE_CLOUD_PROJECT,GCLOUD_PROJECT,GCP_PROJECTservice_account_info["project_id"](if provided)service_account_file’s embedded project_id (if provided)- ADC project detection
API
get_secret(
secret_name: str,
project_id: Optional[str] = None,
version_id: str = "latest",
service_account_file: Optional[str] = None,
service_account_info: Optional[dict] = None,
) -> str
- If both
service_account_infoandservice_account_fileare provided,service_account_infowins. - Secrets are cached in-memory per process (cache key includes which credentials source was used).
Security notes
- Avoid committing service account keyfiles to git.
- Prefer
service_account_infosourced from a secure secret store (CI secrets, vault, etc.). toolssecretdoes not log secret values.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file toolssecret-0.1.0.tar.gz.
File metadata
- Download URL: toolssecret-0.1.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86eba91ac46608ac5fe904e82eafe8a5df01bf21e0825616b5166925c17fe58a
|
|
| MD5 |
7373e8dc99ae9787d8c32cbd8a9bdb68
|
|
| BLAKE2b-256 |
80b303ea010724522e35ce17602eb57461c455a7686f72158a6aa9918179c5a6
|
File details
Details for the file toolssecret-0.1.0-py3-none-any.whl.
File metadata
- Download URL: toolssecret-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dcb26d9470d7ead0abcdc3bf74a43bef328b0e5e9a0e138f3c08ca221f42ad99
|
|
| MD5 |
0f6dee5cbca36956c0274ebb3ad37488
|
|
| BLAKE2b-256 |
24afa274b71cd4d004158d69c80e57b609fae6ecd76d1cbcc874b16540c9252f
|