Skip to main content

Unofficial implementation of 2fas for Python (as a library)

Project description

lib2fas Python

Unofficial implementation of 2fas for Python (as a library). This library serves as the backend for the robinvandernoord/2fas-python CLI, a command-line tool that provides an easy interface to interact with the 2fas TOTP.

Installation

To install this project, use pip:

pip install lib2fas
# or to also install the cli tool:
pip install 2fas

Usage

After installing the package, you can import it in your Python scripts as follows:

import lib2fas

services = lib2fas.load_services("/path/to/file.2fas", passphrase="optional")  # -> TwoFactorStorage

services.generate()  # generate all TOTP keys

gmail = services["gmail"]  # exact match (case-insensitive), returns a list of 'TwoFactorAuthDetails' instances.

github = services.find("githbu")  # fuzzy match should find GitHub, returns a new TwoFactorStorage.

for label, services in github.items():
    # one label can have multiple services!
    for service in services:  # 'service' is a TwoFactorAuthDetails instance
        # Print label, service name, and TOTP code
        print("Label:", label)
        print("Service Name:", service.name)
        print("TOTP Code:", service.generate())  # or .generate_int() to get the code as a number.

The passphrase option of load_services is optional. If you don't provide a password, but your file is encrypted, you will be prompted for the passphrase. If possible, this will be safely stored in the keychain manager of your OS* until the next reboot.

  • Note: only the "Secret Storage" keychain backend on Ubuntu Linux has been tested.

License

This project is licensed under the MIT License.

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

lib2fas-0.1.7.tar.gz (69.9 kB view details)

Uploaded Source

Built Distribution

lib2fas-0.1.7-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file lib2fas-0.1.7.tar.gz.

File metadata

  • Download URL: lib2fas-0.1.7.tar.gz
  • Upload date:
  • Size: 69.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.26.0

File hashes

Hashes for lib2fas-0.1.7.tar.gz
Algorithm Hash digest
SHA256 c393dea769f0b96c9056a5f49ff01cb64ce20fb7642ff99e0d4878aab1705b45
MD5 2be6d551ba2af91cf625417dd735b463
BLAKE2b-256 5e7e3cdf9bda38b49df3519da61ccaef1f29106ec705f6e7f65a4f89eaed7c46

See more details on using hashes here.

Provenance

File details

Details for the file lib2fas-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: lib2fas-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.26.0

File hashes

Hashes for lib2fas-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 21afc452e138137e01be7cf9a368dca59766b1ea244b4d93950aa7132653bf7a
MD5 6ade486768eb60c3b96c01f9225d4654
BLAKE2b-256 4730528b5f7e67c7c814090c2a011f76b88b88de7e0ca2519ea7fdfc3826fed4

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page