Skip to main content

locksmith

Your liaison between repository secrets and the great beyond.

Overview

locksmith acts as an interface between secrets and the Python code using them.

Use case

Consider the following scenario: Your cool new app requires a slick, unique API key to run. Perhaps your framework requires you to put this API key in a manifest.json or AppDelegate file. However, your manifest file(s) need to be checked into GitHub, thus exposing your precious API key. locksmith provides a layer of security to prevent you from having to type out your secrets in plaintext anywhere in your repository.

How it works

locksmith uses GnuPG to encrypt your secrets. Each user in your repository can have their own secrets, either shared among many or unique to each user. Then, locksmith exposes a simple API to access your secrets in code, rather than typing out something like API_KEY = "something_that_shouldn't_be_shared".

Installation

Install with pip:

pip3 install locksmith

Also, make sure you have gpg installed. You can use Homebrew:

brew install gpg

If you'd like to use pinentry too and you're using a Mac, install pinentry-mac:

brew install pinentry-mac

Setup and Background

First, decide on who's going to be using your secrets. locksmith looks for secrets based on users, which are programmer-defined. For example, if I was the only user of my repo, the only user would be wcarhart. However, perhaps you're collaborating on a repo, where you'd have two users, such as wcarhart and friend_user. Or, perhaps you're collaborating on a repo but you'd only like to use one joint user for locksmith, such as locksmith_user.

If you have one user, locksmith_user, add the following file locksmith_user.lcksmth to your repository (but do NOT check it into version control!):

secret0=secret_value0
secret1=secret_value1
...
secretN=secret_valueN

An example of this file with actual values could be:

API_KEY=3eWhJtewSr0sSshNX9STOLUV1nGtFznxQM8UfyYH
DATABASE_USER=admin
DATABASE_AUTH=password

If you named this file locksmith_user.lcksmth, then these secrets will be available to the user locksmith_user, or to any user that knows locksmith_user's password.

Now, encrypt the file using gpg:

gpg -c locksmith_user.lcksmth

Enter a desired password. This will produce a file locksmith_user.lcksmth.gpg. You can now safely check this into your version control.

Usage and API

Usage

First, make sure to include locksmith in your Python code:

from locksmith import Locksmith

Then, make a Locksmith object based on what user(s) you have defined:

l = Locksmith("locksmith_user")

When the above line is executed, you will be prompted for locksmith_user's password. This will happen only when you instatiate a new Locksmith object and not every time you access a secret.

API

locksmith exposes the following API for you to use:

get_secret(parameter)

The get_secret function allows you to get a specific secret, specified by parameter. Use it like this:

secret_value = l.get_secret("API_KEY")

If you pass in an invalid parameter, locksmith will raise a ValueError or LookupError.

Metadata

Release files for locksmith 1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for locksmith 1.1
File Interpreter ABI Platform
locksmith-1.1-py3-none-any.whl Python 3 none any Details

Release files / locksmith-1.1-py3-none-any.whl

Download URL locksmith-1.1-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5c73af27c4f377fc9f25c50c3516d150c0d805612ac846c1eba8f3cdae9877aa
BLAKE2b-256 checksum
How to use checksums
f231598d20db9eddae2da2c28422165d36f3f0aa1e4190f92d79f04f361412f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5

Release history Release notifications | RSS feed

This release

1.1 This release

1 release file

1.0

1 release file

0.5

1 release file

0.4

1 release file

0.3

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page