Skip to main content

Auditable random credential generator for AI agents and machine-readable pipelines (Python wrapper around the secretgenerator CLI).

Project description

secretgen (Python)

pypi python

Auditable random credential generator for AI agents and machine-readable pipelines. This Python package wraps the secretgenerator CLI and exposes its stable schema-v1 JSON output as Python dicts.

Install

The Python package and the CLI binary install separately:

pip install secretgen

The PyPI package is named secretgen (not secretgenerator) because a secret-generator package already exists on PyPI; the import name matches and is also secretgen.

Then install the CLI once with whichever method fits your environment:

npm install -g @secretgenerator/cli
# or
brew install rafaelperoco/tap/secretgenerator
# or
go install github.com/rafaelperoco/secretgenerator/cmd/secretgenerator@latest

Quick start

import secretgen as sg

pw = sg.password(length=24, charset="alphanum-symbols-v1",
                 require_classes="lower,upper,digit,symbol")
print(pw["password"], "—", pw["entropy_bits"], "bits")

phrase = sg.passphrase(words=8, separator="-")
print(phrase["password"])

token = sg.api_key(length=40, prefix="sk_live")
print(token["password"])

bits = sg.entropy("Tr0ub4dor&3")["entropy_bits"]
print(f"that pasword has {bits:.1f} bits")

Every function returns a parsed schema-v1 dict with the same shape as the CLI's --json output (see schemas/output-v1.json).

Error handling

try:
    sg.password(length=4)  # below the 80-bit floor
except sg.SecretgeneratorError as e:
    if e.code == "E_ENTROPY_TOO_LOW":
        # Stable code; safe to branch on.
        ...

The code attribute exposes a stable identifier from the CLI's error envelope (E_ENTROPY_TOO_LOW, E_CHARSET_EMPTY, E_CLASS_IMPOSSIBLE, E_INVALID_ARGS, E_RNG_FAILURE).

Why a wrapper instead of a pure-Python implementation?

Cryptographic primitives belong in audited binaries with reproducible builds and SLSA provenance, not duplicated across language wrappers. The CLI is signed end-to-end with cosign keyless (Sigstore/Fulcio + GitHub OIDC) and ships SLSA Level 3 attestation. This wrapper is a thin transport — it parses JSON.

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

secretgenerator_py-2.0.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

secretgenerator_py-2.0.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file secretgenerator_py-2.0.0.tar.gz.

File metadata

  • Download URL: secretgenerator_py-2.0.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for secretgenerator_py-2.0.0.tar.gz
Algorithm Hash digest
SHA256 093db6fe2d609550e6a16c0a5642512b90829787ed26f4c498372af6e8a77bbb
MD5 45474b9008aaf2c0bed015cc49a81ff1
BLAKE2b-256 03b10e54925cb0df19fef861c3d0bb87caf16d117f546a09cdc5ca6059ba0fba

See more details on using hashes here.

File details

Details for the file secretgenerator_py-2.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for secretgenerator_py-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b2fc2e3d6826b85f138407248f87bc1be2b1bb92bcf257c5ca13d8645ed39ae1
MD5 d0b7716c78ecac6a2ed303a3a27d49a6
BLAKE2b-256 688469ffff03d620cfa332f2893d7b76afdbd1635ae1ea219ab172cb8259ef79

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