Skip to main content

Totpy - CLI TOTP generator and management tool

Project description



Totpy is CLI TOTP generator and management tool for Linux and MacOS. Can generate a TOTP token from a given secret key or from one stored in the configuration file. The secrets can be added to the configuration file using a secret key or the QR code image of a secret key. The default configuration file is stored in ~/.local/config/totpy, but can be overriden with a given one.


Totpy requires the follow packages:

Totpy can be installed from this repository using pip:

$ pip install git+

From the Python Package Index using pip:

$ pip install totpy

Or cloning this repository and running

$ git clone
$ python install --user

in all cases It installs the module and the CLI tool.


-c --conf PATH

Overrides the configuration stored in ~/.local/config/totpy/config.json and uses the new file from now on. Check config.example for more info.

$ totpy -c conf.json foo

-a --add NAME

Adds a new secret to the config file. The new secret can be added using a QR code image:

$ totpy -a foo -q foo.png

Or passing directly the secret using the -s option:

$ totpy -a foo -s JBSWY3DPEHPK3PXP

If the entry already exists it will be overwriten.

-r --remove NAME

Removes the given entry from the configutarion file.

$ totpy -r foo

-qr NAME

Generates a QR code for the given name and prints it in the terminal.

$ totpy -qr foo

-l --list

Shows all the entries' names in the configuration file.

$ totpy -l

-s --secret

Generates a TOTP token for the given secret key.



Copies the TOTP token to the clipboard.

$ totpy --copy -s JBSWY3DPEHPK3PXP

$ totpy --copy granada


Generates a TOTP token using the secret stored in the configuration file for the given name.

$ totpy granada

Totpy module

Totpy includes three classes:

  • Base: A helper class for managing the configuration file.
  • Totpy: The class that defines the totpy CLI tool behaviour.
  • Totp: The class that generates the token.

Totp class

This can be imported in your project and used. This is the source code:

class Totp(object):
  """docstring for Totpy"""
  def __init__(self, secret):
    self.secret = secret

  def getHotpToken(self, interval):
    key = base64.b32decode(self.secret, True)
    msg = struct.pack(">Q", int(time.time()) // interval)
    h =, msg, hashlib.sha1).digest()
    o = h[19] & 15
    h = (struct.unpack(">I", h[o:o+4])[0] & 0x7fffffff) % 1000000
    return h

  def getTotpToken(self):
    return self.getHotpToken(interval=30)


This is free and open source software. You can use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of it, under the terms of the MIT License. See LICENSE.txt for details.

This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or implied. See LICENSE.txt for details.


To report bugs, suggest improvements, or ask questions, please create a new issue at .

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for totpy, version 0.3.2
Filename, size File type Python version Upload date Hashes
Filename, size totpy-0.3.2.tar.gz (5.2 kB) File type Source Python version None Upload date Hashes View

Supported by

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