Skip to main content

TFA CLI Tool

A command-line tool for managing two-factor authentication (2FA) TOTP codes.

Why did I build this?

  • I wanted to understand how TOTP codes work. I don't like trusting access to my accounts to a black box which I don't understand.
  • I don't keep my phone with me all the time.
  • I'm worried about losing access to my accounts if I lose my phone.

This project succeeded in its main goal: I now have a good understanding of how TOTP codes work.

Should you use this?

Maybe? Standard practice is to keep two-factor authentication codes on your phone, not your computer. This separation is intentional - if someone gains access to your computer, they still won't have your 2FA codes. By storing codes on your computer with this tool, you're reducing that security boundary. The security model assumes phones have better protection against unauthorised access than computers do.

The secret database is not encrypted. Secrets are stored in an sqlite database. You should keep backups, and probably use the qr code feature to add accounts to an authenticator app.

I'm also not a security expert. I'm just a programmer who wanted to understand TOTP. Maybe you should use a standard tool instead.

Use at your own risk.

Installation

uv tool install tfa

or

pip install tfa

There is no default location for the database because the point is to make secret management less opaque than typical authentication apps. You must explicitly choose where to store your secrets by setting a path in your shell configuration:

export TFA_STORAGE=~/.config/tfa/accounts.db

For one-off commands, use --storage to override TFA_STORAGE:

tfa --storage ./dev-accounts.db import -
tfa import --storage ./dev-accounts.db -
tfa list --storage ./dev-accounts.db

If neither TFA_STORAGE nor --storage is set, the tool will display an error message and exit.

Migrating from JSON

If you're upgrading from a previous version that used JSON storage, TFA will automatically detect this and provide migration instructions. To migrate your accounts:

tfa import ~/.config/tfa/accounts.json
export TFA_STORAGE=~/.config/tfa/accounts.db

After verifying that all your accounts were successfully migrated, you can safely remove the old JSON file.

Usage

Add a new account

tfa add <account_name> <secret_key>

# With custom issuer name
tfa add <account_name> <secret_key> --issuer "Custom Name"

# Force overwrite existing account
tfa add <account_name> <secret_key> -f

# From a QR code image (keeps issuer, digits, period and algorithm)
tfa add <account_name> --qr qr.png

# From a QR code image on stdin, eg. a screenshot on the clipboard
wl-paste | tfa add <account_name> --qr -                                    # Wayland
xclip -selection clipboard -t image/png -o | tfa add <account_name> --qr -  # X11

Get TOTP code

tfa code <account_name>

List accounts

tfa list

Remove account

tfa remove <account_name>

Generate QR Code

Generate a QR code to scan with other authenticator apps:

tfa qr <account_name>

Import/Export Accounts

Export accounts to JSON (useful for backups):

# Export to stdout
tfa export

# Export to a file
tfa export backup.json

# Explicitly export to stdout
tfa export -

Import accounts from JSON. Imports add to existing accounts; existing accounts are skipped unless --force is used:

# Import accounts from a file
tfa import backup.json

# Import accounts from stdin
tfa import -

# Replace existing accounts with matching names
tfa import backup.json --force

Examples

# Add a new GitHub account
tfa add github JBSWY3DPEHPK3PXP --issuer "GitHub"

# Get current code
tfa code github
# Output: GitHub: 123456

# List all accounts
tfa list
# Output: github

# Generate QR code
tfa qr github

Metadata

Release files for tfa 0.5.0

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

Source distribution (sdist)

Source distribution for tfa 0.5.0
File Size Uploaded Provenance Actions
tfa-0.5.0.tar.gz 11.2 kB Without provenance Details for tfa-0.5.0.tar.gz

Built distribution (wheel)

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

Total release size: 19.6 kB

Release files / tfa-0.5.0.tar.gz

Download URL tfa-0.5.0.tar.gz
Size 11.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c73f28ea57401c523b39fb3d7e168d6332435f6e8979502c349431d9a6be3228
BLAKE2b-256 checksum
How to use checksums
499ffd26f41e4a03c077cc10cd711a1aa271874ceba1d833b765f9d0475529fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.24

Release files / tfa-0.5.0-py3-none-any.whl

Download URL tfa-0.5.0-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e8f71e59825f643048edfe5aaae26c65e9e24356d27df4b946b2e37c88cf237b
BLAKE2b-256 checksum
How to use checksums
e23455c46241d940f86a2f48ce53fcfbcb7730b607e11b4cd317814862add50c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.24

Security for tfa 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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