Diceware

1.0.1 · active · verified Sat Apr 11

Diceware is a Python library and command-line tool for generating secure, memorable passphrases using the Diceware method. It generates passphrases by concatenating words randomly picked from wordlists. The library supports various sources of randomness, including Python's `SystemRandom` by default, and allows for different wordlists, including the EFF wordlist. It also offers options for capitalization and special characters. The current version is 1.0.1, actively maintained with recent updates.

Warnings

Install

Imports

Quickstart

Generate a Diceware passphrase using the `get_passphrase` function by providing an `options` object that mimics `argparse.Namespace`. The example uses default settings for a 6-word passphrase with capitalized words and no special characters or delimiters, leveraging the EFF wordlist and `SystemRandom`.

from types import SimpleNamespace
from diceware import get_passphrase

# Mimic argparse options for programmatic use
options = SimpleNamespace(
    num=6,          # Number of words (default: 6)
    caps=True,      # Capitalize words (default: True)
    specials=0,     # Number of special characters (default: 0)
    delimiter="",   # Delimiter between words (default: "")
    randomsource="system", # Source of randomness (default: "system")
    wordlist=["en_eff"], # Wordlist name(s) (default: "en_eff")
    infile=None     # Optional custom input wordlist file descriptor
)

passphrase = get_passphrase(options=options)
print(passphrase)

view raw JSON →