Metadata-Version: 2.4
Name: lib2fas
Version: 0.1.8
Summary: Unofficial implementation of 2fas for Python (as a library)
Project-URL: Documentation, https://github.com/robinvandernoord/lib2fas-python#readme
Project-URL: Issues, https://github.com/robinvandernoord/lib2fas-python/issues
Project-URL: Source, https://github.com/robinvandernoord/lib2fas-python
Author-email: Robin van der Noord <robinvandernoord@gmail.com>
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Python: >=3.10
Requires-Dist: configuraptor>=1.26.1
Requires-Dist: cryptography
Requires-Dist: keyring
Requires-Dist: pyjson5
Requires-Dist: pyotp
Requires-Dist: rapidfuzz
Provides-Extra: dev
Requires-Dist: edwh; extra == 'dev'
Requires-Dist: hatch; extra == 'dev'
Requires-Dist: pytest-mypy-testing; extra == 'dev'
Requires-Dist: python-semantic-release<8; extra == 'dev'
Requires-Dist: su6[all]; extra == 'dev'
Description-Content-Type: text/markdown

# lib2fas Python

Unofficial implementation of 2fas for Python (as a library).
This library serves as the backend for
the [robinvandernoord/2fas-python](https://github.com/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:

```bash
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:

```python
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.
