Skip to main content

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_file supports ~ 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:

  1. GOOGLE_CLOUD_PROJECT, GCLOUD_PROJECT, GCP_PROJECT
  2. service_account_info["project_id"] (if provided)
  3. service_account_file’s embedded project_id (if provided)
  4. 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_info and service_account_file are provided, service_account_info wins.
  • 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_info sourced from a secure secret store (CI secrets, vault, etc.).
  • toolssecret does 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

toolssecret-0.1.1.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

toolssecret-0.1.1-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file toolssecret-0.1.1.tar.gz.

File metadata

  • Download URL: toolssecret-0.1.1.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for toolssecret-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f4ddd57f07f88f93ccc979e5b336f16aa57b63b2a83647152763f15c3bb65fbd
MD5 4fae4cbdd7f066ccb77b3651487a4331
BLAKE2b-256 ac24a5d1b7532af266a3e17ff75125100d225c26939915eb9887f082f7b3386a

See more details on using hashes here.

File details

Details for the file toolssecret-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: toolssecret-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for toolssecret-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d6b526f6da67d4d406bcc1f6ffd5ce1432e11afffac0c528987e296fba83d89f
MD5 2d95172a0ee7b4958189c634e74bbe76
BLAKE2b-256 63536bf2d9be84cfcc7fef57acfe60433201e7f2973c67e15b498c2582d4de04

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page