Skip to main content

A python wrapper around oathtool

Project description


A python wrapper script around oathtool to allow for easy OTP code generation on the command line.

This project was born out of my frustration of having many many 2-Factor accounts on my mobile phone, which did not present a quick and easy mechanism to generate and use codes.

Developed and tested mainly on MacOS.


pip install py_oathtool


  • Python packages
    • subprocess32
    • pyaml

oathtool should be available on the PATH

  • Mac: brew install oath-toolkit

Clipboard support on MacOS is supported by pbcopy which is installed by default. For Linux install xclip


List the configured accounts with the -l switch.

$ otp -l

Generate an OTP by providing the account name. The script will provide the OTP code, and also drop it to the clipboard.

$ otp aws-account-dev
Valid for 18 more seconds
(On the clipboard!)

If a code is only valid for a short duration the script will pause until the next 30-second window begins.

$ otp cr-dev
Short lived OTP. Holding off for 4 seconds...
Valid for 30 more seconds
(On the clipboard!)

Read about all options

$ otp -h

Declaring accounts

Two pieces of information are required for each account:

  • An account name / label
  • Your 64 character oath secret provided by the 3rd party. This is typically a QR code, but websites often also offer the string.

The script will read these values from a config file sourced from, by default, ~/.otp-secrets.yaml in the following format:


Additionally, the following configuration options are supported in the ~/.otp-secrets.yaml file:

  • holdoff: Specify a different holdoff value to wait for the next code
  • use_clipboard: Disable putting the code on the clipboard


Autocompletion support can be added through use of the -t flag.

For zsh support, add the following to your .zshrc file:

compdef _otp otp
_otp() {
  compadd `otp -t`


Activate the pipenv with the --dev flag

pipenv --three
pipenv install --dev
pipenv shell

Build the packages

python sdist bdist_wheel

Upload to PyPI

twine upload --repository-url dist/*


2-Factor is meant to provide an extra layer of account security and this tool does not exactly promote that concept. You should be responsible for taking reasonable steps to protect your secrets file, and perhaps this is not the ideal 2-Factor solution for your most important accounts.

I take no responsibility if you lose accounts through using this tool.

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

py_oathtool-1.1.0.tar.gz (5.5 kB view hashes)

Uploaded source

Built Distribution

py_oathtool-1.1.0-py2.py3-none-any.whl (5.4 kB view hashes)

Uploaded py2 py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page