Skip to main content

py2fa-cli

PyPI version PePy downloads

Calculates and displays time-based one-time passwords (TOTP) for two-factor authentication:

$ py2fa pypi.org
One-time password: 123456 (valid for 13.7 seconds)

Installation

For typical use:

python3 -m pip install py2fa-cli

For development:

git clone https://github.com/arcctgx/py2fa-cli
cd py2fa-cli
python3 -m pip install --editable .

Dependencies

  • pyotp
  • pyxdg

These dependencies will be installed automatically when py2fa-cli is installed by pip.

Configuration

TOTP secrets are stored in user's XDG configuration directory. Unless you changed your XDG_CONFIG_HOME, that will be .config/py2fa/secrets.json in your $HOME. The secrets file must not be world-accessible (readable, writable or executable): in such case py2fa will refuse to load it.

The secrets file is a dictionary represented in JSON format, e.g.:

{
    "pypi.org": "MYPYPITOTPSECRET",
    "test.pypi.org": "MYTESTPYPITOTPSECRET",
    "example.com": "otpauth://totp/ExampleLLC:you@example.com?secret=HUNTER2&issuer=ExampleLLC&period=15"
}

The dictionary key is what you provide in the command-line, so just use any name that's convenient. The value is the shared TOTP secret in base32 format, or an otpauth:// URI.

A note for Microsoft Authenticator users

It is not possible to extract the shared secret from the Microsoft Authenticator application once it's been configured. You can only obtain the shared secret during the initial setup of the authenticator app.

When setting up 2FA and presented with a QR code, do not scan it directly with Microsoft Authenticator. Instead, use a generic QR code scanner app to retrieve the otpauth:// URI, which will look similar to the example shown above. Store this URI in your secrets.json file. Afterward, you can still scan the QR code with Microsoft Authenticator if desired - both py2fa and the app will generate the same TOTP codes.

A known issue with otpauth:// URIs generated by Microsoft MFA is that they may not fully comply with the URI specification: the issuer parameter may differ from the issuer label. To work around this, you can either manually align the issuer parameter with the issuer label in your configuration file, or simply remove the issuer parameter from the URI.

The example in the Configuration section above shows a compliant URI, where the issuer label (the part immediately following totp/ and before the colon) matches the value of the &issuer= parameter.

Metadata

Release files for py2fa-cli 1.1.1

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

Source distribution (sdist)

Source distribution for py2fa-cli 1.1.1
File Size Uploaded
py2fa-cli-1.1.1.tar.gz 15.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py2fa-cli 1.1.1
File Interpreter ABI Platform
py2fa_cli-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 32.7 kB

Release files / py2fa-cli-1.1.1.tar.gz

Download URL py2fa-cli-1.1.1.tar.gz
Size 15.9 kB
Tags Source
SHA-256 checksum
How to use checksums
10e80acd30f6a2cdc8661069f9f3b2129419faf3b27825d12c940cd5388ed375
BLAKE2b-256 checksum
How to use checksums
819252744994bb9f8200b8d5a878bac7dd0f7f44dcd07b4108f421ca3c83403b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.2

Release files / py2fa_cli-1.1.1-py3-none-any.whl

Download URL py2fa_cli-1.1.1-py3-none-any.whl
Size 16.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
33400eb4adf3553e0979835c0cd4f5ca888b7a68c24b0d018dfd03ee7b8058c3
BLAKE2b-256 checksum
How to use checksums
362805c0f6c49e77894b4ba13e50896a007ec16a3f38cbc85d58627958c40c40
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.2

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files

1.1.0

2 release files

1.0.1

2 release files

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