Package: secrethub
SecretHub Client for PythonBETAThis repository provides a Python client for the SecretHub Secrets Management API.SecretHubis a secrets management tool that works for every engineer and allows you to securely provision passwords and keys throughout your entire stack with just a few lines of code.Table of ContentsInstallationUsageGetting helpBETADevelopingInstallationTo install the SecretHub package from PyPi, run the following command:python-mpipinstallsecrethubThe package supports Linux, Windows (32 and 64 bit) and MacOS.
It is built for CPython versions 3.5 and above.Make sure you have created a SecretHub account and set up a credential on your system before using the library. See theCredentialsection for more info.Note that passphrase protected credentials are not supported by the Python client.UsageBefore doing any calls to the library, you need to import thesecrethubpackage and create a client:importsecrethubclient=secrethub.Client()After you have your client, you can call the following methods:read_string(path)Retrieve a secret value as a string.secret=client.read_string("path/to/secret")read(path)Retrieve a secret, including all its metadata.secret=client.read("path/to/secret");The returned object is of thesecrethub.SecretVersiontype and it represents a version of a secret with the sensitive value stored in thedatafield.
It provides the following fields:secret_version_idsecretversiondatacreated_atstatusexists(path)Check if a secret exists atpath.secret_exists=client.exists("path/to/secret")write(path, secret)Write a secret value to a givenpath.client.write("path/to/secret","secret_value")remove(path)Delete the secret found atpath.client.remove("path/to/secret")resolve(ref)Resolve a secret reference tag of the formatsecrethub://<path>and return the corresponding secret value. Ifrefis not a valid reference tag, it returns otherwise it returnsrefunchanged.resolved_ref=client.resolve("secrethub://path/to/secret")resolve_env()Return a dictionary containing the OS environment with all secret references (secrethub://<path>) replaced by their corresponding secret values.Exampleos.environ['MY_SECRET']='secrethub://path/to/secret'os.environ['OTHER_VARIABLE']='some other value'resolved_env=client.resolve_env()print(resolved_env)# Prints all environment variables with any secret references resolved to their corresponding value# {#    'MY_SECRET': 'the value of the secret stored at path/to/secret',#    'OTHER_VARIABLE': 'some other value'# }export_env(env)Adds the environment variables defined in theenvdictionary to the environment of the process.
If any of them are already present in the environment, they will be overwritten.This method can be used together withresolve_envto resolve all environment variables with secret references and set them to their corresponding secret value. Note that we recommend you useclient.resolve_env()for most cases, but if your code reads its configuration from the environment and cannot be adapted to use the result ofclient.resolve_env()directly you can use it together withexport_env().Exampleos.environ['MY_SECRET']='secrethub://path/to/secret'client.export_env(client.resolve_env());print("secret: "+os.environ['MY_SECRET']);# Prints the value of the secret stored at path/to/secret.ExceptionsAny error encountered by the SecretHub client will be thrown as aRuntimeErrorwith the full error message as an associated string value.try:client.read('path/to/secret')exceptExceptionase:print(e)CredentialTo use the SecretHub Python client, you need to provide a credential for yourSecretHubaccount.
You can sign up for a free developer accounthere.After signup, the credential is located at$HOME/.secrethub/credentialby default.secrethub.Client()automatically uses this credential.You can also provide a credential through theSECRETHUB_CREDENTIALenvironment variable.Getting HelpCome chat with us onDiscordor email us atsupport@secrethub.ioBETAThis project is currently in beta and we'd love your feedback! Check out theissuesand feel free suggest cool ideas, use cases, or improvements.Because it's still in beta, you can expect to see some changes introduced. Pull requests are very welcome.For support, send us a message onDiscordor send an email tosupport@secrethub.ioDevelopingNote that most of the code in this repository is automatically generated from theSecretHub XGO project, which wraps thesecrethub-goclient withcgoexported functions so it can be called form other languages, e.g. C, C#, Python, Ruby, NodeJS, and Java. To generate the codeSWIGis used.See theSecretHub XGO repositoryfor more details.